Anyname Donotcare
Anyname Donotcare

Reputation: 11403

get data from data table under some condition

Q:

I have a DataTable , i want to get data according to some condition.(Where())

MyTable.Select().Where()

How to do this if the condition (type = 0).

Upvotes: 1

Views: 887

Answers (2)

Dan Waterbly
Dan Waterbly

Reputation: 850

This should be what you are looking for:

var query = from r in dataset.Tables[0].AsEnumerable()
where r.Field<int>("Type") == 0
select new
{
     r.Field<string>(“Column1”), 
     r.Field<string>(“Column2”),
     r.Field<string>("ColunmEtc")
}

Upvotes: 1

SLaks
SLaks

Reputation: 887777

You can use LINQ:

IEnumerable<DataRow> rows = MyTable.AsEnumerable()
                                   .Where(row => row.Field<int>("type") == 0);

Upvotes: 3

Related Questions