Harsh
Harsh

Reputation: 165

Filter of my datatable

I tried this code for filter but not work

My datatable looks like this

    ID       Name         Age
    1        Harsh         6
    2        Prasann       5

My code:

dt = dsDecEjID.Tables(0).select ("Age between 6 and 7")  

This code causes an error for between condition.

How to add between condition in datatable.select?

Upvotes: 2

Views: 115

Answers (3)

Nag
Nag

Reputation: 689

You can do like this

DataRow[] drs = dsDecEjID.Select("Age >= 6 AND Age <= 7");
DataTable dt2 = dsDecEjID.Clone();
 foreach (DataRow d in drs) 
{
    dt2.ImportRow(d);
}

Upvotes: 0

Jack
Jack

Reputation: 235

You can use like

string age = "(6,7)";
DataRow[] drow = dsDecEjID.Tables[0].Select("Age between " + age );

Upvotes: 1

Mike Perrenoud
Mike Perrenoud

Reputation: 67898

There is no between syntax for the DataView.RowFilter. You need to change that to:

[Age] >= 6 AND [Age] <= 7

Upvotes: 3

Related Questions