468,168 Members | 1,504 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,168 developers. It's quick & easy.

HELP: DataView does NOT filter :-(

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

Nov 16 '05 #1
1 1505
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
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

Nov 16 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Trey | last post: by
1 post views Thread by Jay Zweedyk | last post: by
4 posts views Thread by James | last post: by
7 posts views Thread by Bernie Hunt | last post: by
1 post views Thread by gcdp | last post: by
reply views Thread by kamranasdasdas | last post: by
reply views Thread by gcreed | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.