a problem with DataView

CLRBOY

Member
Joined
Dec 15, 2004
Messages
11
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 doesnt 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.....
 
Not sure what youre doing with the DataView after you apply the filter, but...
If you want to get at a particular row and its data (and not for binding), then the Select method is quite a bit faster:

C#:
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
        // Dont delete in here, this is a foreach :)
    }
}
 
Back
Top