Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Getting Rowcount in DataView 1

Status
Not open for further replies.

RamHardikar

Programmer
Feb 16, 2001
109
GB
DataSet Ds1 has undergone some updates on the column ‘Flag’. Am trying to create a DataView of only those rows which have the Flag value as ‘True’. Below is my code where i try to filter the required rows. Also am trying to get the row count of the DataView. But I always get the incorrect value or rather it always shows me the same rowcount as that of my DataSet ds1, which has 200 rows.

Why don’t I get the correct count even after I set rowfilter and rowstate filter on the DataView?

Code -

----------------------
dv1 = new DataView();

dv1.Table = ds1.Tables["People_Test"];
dv1.RowFilter = "flag = 'True'";
dv1.RowStateFilter = DataViewRowState.ModifiedCurrent;
dv1.Sort = "id Asc";

iDVRowCount = dv1.Table.Rows.Count;

----------------------
 
seems that's because you're datasource still has 200 records...you're only viewing based on that filter though...

"...we both know I'm training to become a cagefighter...see what happens if you try 'n hit me..."
 
but when i bind a DataGrid to this DV it shows the correct number of rows (after filtering out the Falg=False ones) in the grid. so why doesnt it show the correct count when i do 'dv.table.rows.count'?
 
Because when you bind it to the grid, it shows the filtered view. The filter only contains certain records but the DataView still contains all of the records.

Why don't you just count the rows in the datagrid?

--------------------------------------------------------------------------------------------------------------------------------------------

Need help finding an answer?

Try the search facility ( or read FAQ222-2244 on how to get better results.
 
i dont want to use the DataGrid. i had used it just to see if the DV had the correct filtered rows.

isnt there any solution to this problem?
 
So what are you going to to with the filtered rows? Presumably you are filtering them so that you can do somehting with them (i.e. display them to the user?)

--------------------------------------------------------------------------------------------------------------------------------------------

Need help finding an answer?

Try the search facility ( or read FAQ222-2244 on how to get better results.
 
I had the same problem in a vb.net app. ca8msm is correct on two counts.
(1)The dataview is attacted to your dataset and a count on the dataview will always be the same regarless of an applied filter.
(2)You are filtering for some purpose, at some point you are going to display that data.

The only way I got a count of the filtered data was to use a count from the object I bound my filtered data too, which in my case was a list box.
Code:
<listbox>.Items.Count.ToString
 
As ca8msm and jbenson have suggested you cannot get the row count from DataView, but you can use Select method of Table and use the same criteria and get the no of rows for that criteria..

Code:
int i;
DataRow[] drArray;
drArray = ds.Tables[0].Select("Flag='True'");
i = drArray.Length; //Shouls give you the nos of Rows

hope this helps..

Sunil
 
I as trying to implement the 'Check All' functionality (across multiple pages) of the checkbox. So wanted the rowcount of the filtered rows to compare it with the actual rowcount in the DS (since a user cud actually unckeck a checkbox against row(s) across pages).

The solution given by Sunil has helped.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top