arjun
arjun

Reputation: 645

filter datatable on loop

Is there anyway of filtering datatable based on other datatable. something like below:

   foreach (datarow dr in somedatatable.select("id= someothertable.rows["someotherid"])
  {
     dr[somefield]=someothertable[someotherfield];
   } 

Upvotes: 0

Views: 994

Answers (2)

Tigran
Tigran

Reputation: 62265

You can do a ordinary SQL select using DataView

DataView dv = new DataView(dataTableToFilter);
dv.RowFilter = ""//SQL condition 

Complete useful example in your case you can find here:

Creating a DataTable from a DataView

Where you apply a DataView filter to a DataTable and create a new DataTable from filtered rows.

Upvotes: 2

Coofucoo
Coofucoo

Reputation: 119

I have a question, why you want to do the filter logic in your code? Your example logic is very simple.

I order to do filter more efficient, we'd like use database to do that. I think your requirement can be implemented by using a join statement. Do you agree?

Upvotes: 0

Related Questions