考虑下面的代码:
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 设置为 1。
但是即使没有记录被删除,deletedLOVcount 返回值 1。当没有 proci_ID>1 的记录时,addedLOVcount 也一样,它也返回 count as1
最佳答案
DataView
通过 Table
属性引用它的原始 DataTable。但它不共享相同的数据。 DataTable
包含未应用过滤器的原始数据,而 DataView
仅包含应用过滤器后的记录。
您将通过 DataView.Count
获得正确的计数:
int deletedLOVcount = deletedLOV.Count;
MSDN:
Gets the number of records in the DataView after RowFilter and RowStateFilter have been applied.
关于c# - Dataview Table.Rows.Count 在没有这样的行时返回 1,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13698491/