Getting a count of rows in a datatable that meet certain criteria

前端 未结 8 976
不知归路
不知归路 2021-02-01 14:02

I have a datatable, dtFoo, and would like to get a count of the rows that meet a certain criteria.

EDIT: This data is not stored in a database, so using SQL is not an op

相关标签:
8条回答
  • 2021-02-01 14:25

    Not sure if this is faster, but at least it's shorter :)

    int rows = new DataView(dtFoo, "IsActive = 'Y'", "IsActive",
        DataViewRowState.CurrentRows).Table.Rows.Count;
    
    0 讨论(0)
  • 2021-02-01 14:27
    object count =dtFoo.Compute("count(IsActive)", "IsActive='Y'");
    
    0 讨论(0)
提交回复
热议问题