Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
检查某个列中是否存在字符串,我使用类似的东西
mydatatable.AsEnumerable().Any(Function(r) r.Field(Of String)("somecolumn") = "somestring")
但我怎样才能找到的行索引"somestring"?考虑到它只允许存在一次mydatatable,如果它存在不止一次呢?
"somestring"
mydatatable
您可以使用通过索引的重载:
Dim rows = myDataTable.AsEnumerable(). Select(Function(r, i) New With {.Row = r, .Index = i}). Where(Function(x) x.Row.Field(Of String)("somecolumn") = "somestring") If rows.Any() Then Dim firstIndex As Int32 = rows.First.Index End If