So I recently came across this solution in code and was wondering if it is considered an ‘acceptable’ way of retrieving a single row from a Strongly Typed dataset/table.
Basically what we have is something like this:
Dim fooAdapter As New FooDataSetTableAdapters.FooTableAdapter()
Dim fooRow As FooDataSet.FooRow = CType(fooAdapter.GetData().Select("SomeFooField=50")(0), FooDataSet.FooRow)
with fooRow
..
..
end with
Although the code above works my main concern is that calling fooAdapter.GetData() will actually grab all the data in the table before applying the Select() filter which could potentially slow things down over time… Is there a cleaner way to do this or is this way of doing things fine?
Edit:
The filter criteria is not the primarykey field so calling the table’s FindByFooID method will not work…
Use the dataset editor tool to create a query
GetUniqueFoowith the SQL that will filter based onSomeFooField. You can run it by usingfooAdapter.GetUniqueFoo(SomeFooValue).