Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dataview Table.Rows.Count is returning 1 when there is no such rows

Tags:

c#

asp.net

consider the code below:

DataView deletedLOV = new DataView(tbltmp, "prociLOV_Deleted=1", "prociLOV_ID",
                                   DataViewRowState.CurrentRows);
DataView addedLOV = new DataView(tbltmp, "prociLOV_Id>1", "prociLOV_ID",
                                 DataViewRowState.CurrentRows);
int deletedLOVcount=deletedLOV.Table.Rows.Count;
int addedLOVcount=addedLOV.Table.Rows.Count;

prociLOV_Deleted is set to 1 when a record is deleted.

But even when no records are deleted the deletedLOVcount return value 1. Also the same with addedLOVcount when there is no record with proci_ID>1 ,it too returns count as1

like image 711
user1869914 Avatar asked Oct 20 '25 19:10

user1869914


1 Answers

The DataView references it's original DataTable via the Table property. But it does not share the same data. The DataTable contains the original data without the applied filter whereas the DataView contains only the records after the appplied filter.

You would get the correct count via DataView.Count:

int deletedLOVcount = deletedLOV.Count;

MSDN:

Gets the number of records in the DataView after RowFilter and RowStateFilter have been applied.

like image 61
Tim Schmelter Avatar answered Oct 22 '25 08:10

Tim Schmelter



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!