Find row in datatable with specific id

2019-01-13 17:48发布

I have two columns in a datatable:

ID, Calls. 

How do I find what the value of Calls is where ID = 5?

5 could be anynumber, its just for example. Each row has a unique ID.

8条回答
Anthone
2楼-- · 2019-01-13 18:39
DataRow dataRow = dataTable.AsEnumerable().FirstOrDefault(r => Convert.ToInt32(r["ID"]) == 5);
if (dataRow != null)
{
    // code
}

If it is a typed DataSet:

MyDatasetType.MyDataTableRow dataRow = dataSet.MyDataTable.FirstOrDefault(r => r.ID == 5);
if (dataRow != null)
{
    // code
}
查看更多
我只想做你的唯一
3楼-- · 2019-01-13 18:40

You can try with method select

DataRow[] rows = table.Select("ID = 7");
查看更多
登录 后发表回答