If I have a DbCommand
defined to execute something like:
SELECT Column1 FROM Table1
What is the best way to generate a List<String>
of the returned records?
No Linq etc. as I am using VS2005.
If I have a DbCommand
defined to execute something like:
SELECT Column1 FROM Table1
What is the best way to generate a List<String>
of the returned records?
No Linq etc. as I am using VS2005.
Loop through the Items and Add to the Collection. You can use the
Add
methodI think this is what you're looking for.
Not tested, but this should work fine.
If you would like to query all columns
The User's constructor would do all the "dr.GetString(i)"
Or a nested List (okay, the OP was for a single column and this is for multiple columns..):
Where the data returned is a string; you could cast to a different data type: