0

私は以下のデータをデータテーブルに持っています。これはサンプルデータです。通常、データテーブルには1,000万から2,000万行あるため、データテーブルに12,13の出現を取得したいと思います。

Customer  |  quantity  |  Product  | Code 

1         |  3         |  Product  | 12 
2         |  4         |  Product  | 13 
3         |  1         |  Product  | 12 
4         |  6         |  Product  | 13 
4

2 に答える 2

0

シンプルはどうですかfor each loop

private int getCount(int yourSearchDigit)
{
    int counter = 0;
    foreach (DataRow dr in youDataTable.Rows)
    {
        if (Convert.ToInt32(dr["Code"]) == yourSearchDigit)
        counter++;
    }
    return counter;
}
于 2013-01-07T11:02:56.293 に答える
0

使用できますLinq-To-DataTable

int[] allowedCodes = new []{ 12, 13 };
var rows = table.AsEnumerable()
                .Where(r => allowedCodes.Contains(r.Field<int>("Code")));

ただし、データテーブルに 1000 万から 2000 万行ある場合は、データベース自体でフィルタリングを行うことを検討する必要があります。

それらが発生する数を知りたい場合:

int count = table.AsEnumerable()
                 .Count(r => allowedCodes.Contains(r.Field<int>("Code")));
于 2013-01-07T10:22:49.933 に答える