DataTable.Select问题
我有像这样的简单数据表
| 1 | 2 | 3 |
|------|------|------|
| 1966 | 6544 | 1967 |
| 9560 | 3339 | 4968 |
| 0 | 9400 | 1765 |
| 0 | 5479 | 6701 |
例如,我想检查“ 1”列中是否已经存在1966,以及是否存在获取行索引
我这样做的代码
Dim search() As DataRow = table.Select(" '" & i & "' = '" & value & "' ")
'where i is a integer from 1 to 3 and value is a biginteger
If search.Count > 0 Then
'get row index
Else
Console.WriteLine("not found")
End If
最佳答案
除非行索引本身包含在行值中,否则您将不得不放弃Select方法并使用基于游标的方法。如果找到匹配项,此示例将停止循环:
Dim intTargetIndex As Integer = -1
Dim intCursor As Integer = 0
Do Until intCursor = table.Rows.Count OrElse intTargetIndex > -1
If table.Rows(intCursor)(0).ToString() = value.ToString() Then
intTargetIndex = intCursor
End If
intCursor += 1
Loop