Find row in datatable with specific id

前端 未结 8 1744
醉酒成梦
醉酒成梦 2020-12-05 00:07

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 anynu

相关标签:
8条回答
  • 2020-12-05 00:48

    try this code

    DataRow foundRow = FinalDt.Rows.Find(Value);
    

    but set at lease one primary key

    0 讨论(0)
  • 2020-12-05 00:50
    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
    }
    
    0 讨论(0)
提交回复
热议问题