更新时间:2023-01-17 18:01:48
制作一个字符串搜索条件,像这样:
Make a string criteria to search for, like this:
string searchExpression = "ID = 5"
然后使用DataTable
对象的.Select()
方法,像这样:
Then use the .Select()
method of the DataTable
object, like this:
DataRow[] foundRows = YourDataTable.Select(searchExpression);
现在您可以遍历结果,如下所示:
Now you can loop through the results, like this:
int numberOfCalls;
bool result;
foreach(DataRow dr in foundRows)
{
// Get value of Calls here
result = Int32.TryParse(dr["Calls"], out numberOfCalls);
// Optionally, you can check the result of the attempted try parse here
// and do something if you wish
if(result)
{
// Try parse to 32-bit integer worked
}
else
{
// Try parse to 32-bit integer failed
}
}