I have two columns in a datatable:
ID, Calls.
How do I find what the value of Calls is where ID = 5
?
5 could be anynumber, its just for example. Each row has a unique ID.
I have two columns in a datatable:
ID, Calls.
How do I find what the value of Calls is where ID = 5
?
5 could be anynumber, its just for example. Each row has a unique ID.
Hello just create a simple function that looks as shown below.. That returns all rows where the call parameter entered is valid or true.
and simply call it as shown below;
where 5 is the ID. Thanks..
Make a string criteria to search for, like this:
Then use the
.Select()
method of theDataTable
object, like this:Now you can loop through the results, like this:
I could use the following code. Thanks everyone.
Try avoiding unnecessary loops and go for this if needed.
If you want to search by specific ID then there should be a primary key in a table.
try this code
but set at lease one primary key
You can use LINQ to DataSet/DataTable
Since each row has a unique ID, you should use
Single/SingleOrDefault
which would throw exception if you get multiple records back.(Substitute
int
for the type of your ID field)