Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

how do i filter rows comparing them to a variable ?

 

this works

// Filter the dataview

DataView myDataView = myDataSet.Tables["Customers"].DefaultView;

myDataView.RowFilter = "Country = 'Argentina' ";

 

this doesn't work

// Filter the dataview

string arg = "Argentina";

DataView myDataView = myDataSet.Tables["Customers"].DefaultView;

myDataView.RowFilter = "Country = arg ";

 

i just got a (The variable 'arg' is assigned but its value is never used)

warning.....

  • *Experts*
Posted

Not sure what you're doing with the DataView after you apply the filter, but...

If you want to get at a particular row and it's data (and not for binding), then the Select method is quite a bit faster:

 

DataRow[] rows = myDataSet.Tables["Customers"].Select("Country = 'Argentina'");

if (rows.Length > 0)
{
   // Found at least one match:
   foreach(DataRow row in rows)
   {
       // Do something with each matching row
       // Don't delete in here, this is a foreach :)
   }
}

"I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...