0

我在数据表中有以下数据,这是示例数据。我想在数据表中出现 12,13,因为通常数据表中会有 10-20 百万行。

Customer  |  quantity  |  Product  | Code 

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

2 回答 2

0

您可以使用Linq-To-DataTable

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

但是,如果数据表中有 10-2000 万行,则应考虑在数据库本身中进行过滤。

如果您想知道它们出现的数量:

int count = table.AsEnumerable()
                 .Count(r => allowedCodes.Contains(r.Field<int>("Code")));
于 2013-01-07T10:22:49.933 回答
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 回答