Search:
Welcome Guest | Register | Login
logo

DataTable select record in ASP.Net

My data table have following columns

ID     employee     age     city    zip   ........

I want to use select to get only those records where age >= 25 and zip = "10001"

So how to use SELECT on datatable for these two criteria?

  • ASP.Net
  • DataTable
1
 
Asked: 04 Mar 2013
Reputation: 37
Peyton Partida
2 Answers
DataRow[] dataRows = dataTable.Select("age >= 25 AND zip = '10001'");

Note: string values should be in single quote

3
 
Answered: 04 Mar 2013
Reputation: 1,109
Myghty

We can also use DataView, check this

DataView view = new DataView();
view.Table = dataTable;
view.RowFilter = "age >= 25 AND zip = '10001'";

Now your view will have only those records which matches your criteria.

1
 
Answered: 04 Mar 2013
Reputation: 296
Jason Olivera
Login to post your answer