Reputation: 11403
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
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
Reputation: 887777
You can use LINQ:
IEnumerable<DataRow> rows = MyTable.AsEnumerable()
.Where(row => row.Field<int>("type") == 0);
Upvotes: 3