Find row in datatable with specific id

前端 未结 8 1777
醉酒成梦
醉酒成梦 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:45

    Try avoiding unnecessary loops and go for this if needed.

    string SearchByColumn = "ColumnName=" + value;
    DataRow[] hasRows = currentDataTable.Select(SearchByColumn);
    if (hasRows.Length == 0)
    {
        //your logic goes here
    }
    else
    {
        //your logic goes here
    }
    

    If you want to search by specific ID then there should be a primary key in a table.

提交回复
热议问题