0

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];
   } 

2 Answers 2

2

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.

Sign up to request clarification or add additional context in comments.

6 Comments

how is it possible to write sql condition based on some other datatable
first you apply SQL condition to other table, so you have filtered rows inside DataView of that table. After use that DataView to operate on another DataTable.
there is no property called filter
@arjun: as this is a FILTER, you need to apply a WHERE condition only. For example: in your query you want all someid that is more then 100, so you write: dv.RowFilter = "someid>100";
How can I use multiple row in the statement like dv.Rowfilter= "someid =[multiplerows]"
|
0

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?

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.