I am trying to search a datatable for a specific value, which is based on an ID. In sql it would be something like:
Select FIlepath Where ID = 'x'
but so far I have had no luck, I have tried a few methods including passing the entire row into an array and selecting the value from the array but nothing has worked so far.
However I just found the .Where function for searching a datatable and thought this might be the quickest, cleanest way to do things. But it requires a predicate.
The below code is what I have for this at the moment but I think the problem is with the "ofString" part of the code.
objDataTable_FailCodeDetails.Select(("FilePath")).Where(Of String("ID ='" & i - 1 & "'"))
Any help would be greatly appreciated.
cheers.
The DataTable object has a simple and straightforward method to extract DataRows that satisfy a WHERE condition
DataRows[] rows = objDataTable_FailCodeDetails.Select("ID ='" & i - 1 & "'")
This assumes that the ID field is a text field, so you need the single quotes around the i value, but if it is a simple integer then you write
DataRows[] rows = objDataTable_FailCodeDetails.Select("ID =" & i - 1)
Instead if you want to use a Linq expression it would be
Dim result = objDataTable_FailCodeDetails.AsEnumerable() _
.Where(Function(x) _
x.Field(Of String)("ID") = (i - 1).ToString())
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.