HELP: DataView does NOT filter :-(

W

werk

For limiting access to the database to strictly necessary I try to
filter the query by using DataView.

Thw DataSet ds contains three columns (fields) : (LAND_ID, Landcode,
Landnaam) and four rows.
I try to filter out only one country (key is LAND_ID) with the
following code:

DataTable dt = ds.Tables[0]; // ds contains the dataset of the query
4 rows
DataView dv = new DataView(); // create a new Dataview instance
dv.Table = dt; // copy the table into dv
dv.Table.TableName = "hello"; // set an name (optional ???)
dv.AllowDelete = true; // required ??? ( tried also without
this line)
dv.AllowEdit = true; // required ??? ( tried also without
this line)
dv.AllowNew = true; // required ??? ( tried also without
this line)
dv.RowFilter = "LAND_ID = 8"; // Selection filter
dv.RowStateFilter = DataViewRowState.ModifiedCurrent; // required ???
( tried also without this line)
dv.Sort = "LAND_ID"; // sort

After executing this code the dv.Table still contains 4 rows and not
one as it should be.

I tried again with the constructor:
dv = new DataView(dt, "LAND_ID = 8", "LAND_ID",
DataViewRowState.ModifiedCurrent);
with the same (wrong) result.

What did I wrong ?

Thanks Klaas
 
G

Guest

Hi,

Your problem lies in your foundation about DataTable filtering.

Your DataTable (dv.Table) will still contains all rows.
Only DataView can: filter by expression or state, sort and do
some edition-allowings.

try "dv.Count" to check your "dv.RowFilter"

HTH
Marcin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top