I use code such as the following to search a Dataset datatable:
The problem is that if the searchTerm is not in the dataset, an exception is thrown by the select method. I want the function to allow such searches and deal with them, so I quickly thought of catching errors, something like this:
Using try... catch in this way seems wrong to me. Is there a better way to search a dataset/datatable when Im not sure if the search term is in the data table?
Any help would be appreciated.
Thank you.
Code:
dim returnValue as string
dim rowsFound as datarow()
rowsFound = MyDataSet.Tables(0).Select("FirstName = " & searchTerm & "")
returnValue = rowsFound(0).item("LastName") rowsFound(0) just for simplicity, here.
return returnValue
The problem is that if the searchTerm is not in the dataset, an exception is thrown by the select method. I want the function to allow such searches and deal with them, so I quickly thought of catching errors, something like this:
Code:
dim returnValue as string
dim rowsFound as datarow()
try
rowsFound = MyDataSet.Tables(0).Select("FirstName = " & searchTerm & "")
returnValue = rowsFound(0).item("LastName")
catch ex as exception
returnValue = "none"
end try
return returnValue
Using try... catch in this way seems wrong to me. Is there a better way to search a dataset/datatable when Im not sure if the search term is in the data table?
Any help would be appreciated.
Thank you.