Sign In| Join
Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Jan 28, 2013 12:43 AM by Decker Dong - MSFT
Member
74 Points
94 Posts
Jan 26, 2013 06:03 AM|LINK
I have one datatable i.e.
Rank Name City 1 Jeeten Vadodara 2 Deep Vadodara 3 Bhaumik Vadodara 4 Mihir Ahmedabad
And one dataset i.e.
Rank 2 3
So now, I want to filter datatable based on this dataset. I should get result :
Rank Name City 2 Deep Vadodara 3 Bhaumik Vadodara
All-Star
118619 Points
18779 Posts
Jan 28, 2013 12:43 AM|LINK
Hi,
1) Just please use foreach to loop each row of the DataTable in the DataSet to fetch out all the Rand's ID into a List<int>.
2) And then use LINQ-TO-OBJECT (But first please use SqlDataAdpater.Fill into a DataTable).
3) In the end, please use LINQ-TO-OBJECT:
var result = from row in DataTable.AsEnumerable() where List<int>'s InstanceName.IndexOf((int)row["Rank"])>=0 4) You can use the result.
jeeten.parma...
Member
74 Points
94 Posts
Filter Datatable based on Dataset Values...
Jan 26, 2013 06:03 AM|LINK
I have one datatable
i.e.
Rank Name City
1 Jeeten Vadodara
2 Deep Vadodara
3 Bhaumik Vadodara
4 Mihir Ahmedabad
And one dataset
i.e.
Rank
2
3
So now, I want to filter datatable based on this dataset.
I should get result :
Rank Name City
2 Deep Vadodara
3 Bhaumik Vadodara
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: Filter Datatable based on Dataset Values...
Jan 28, 2013 12:43 AM|LINK
Hi,
1) Just please use foreach to loop each row of the DataTable in the DataSet to fetch out all the Rand's ID into a List<int>.
2) And then use LINQ-TO-OBJECT (But first please use SqlDataAdpater.Fill into a DataTable).
3) In the end, please use LINQ-TO-OBJECT:
var result = from row in DataTable.AsEnumerable()
where List<int>'s InstanceName.IndexOf((int)row["Rank"])>=0
4) You can use the result.