Reputation: 58
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...
Upvotes: 0
Views: 5648
Reputation: 46
Use the dataset editor tool to create a query GetUniqueFoo
with the SQL that will filter based on SomeFooField
. You can run it by using fooAdapter.GetUniqueFoo(SomeFooValue)
.
Upvotes: 3