How can I move results from a SQL Query into Array or Collection in C#?
My SQL Query (selecting LastName values with non-null values from LastName column in mytable):
SELECT LastName FROM mytable WHERE LastName IS NOT NULL
And here is code that I was executing before to generate new Dataset with that column:
string connectionString = @"Data Source='/path-to-datatable/ASTS.sdf';";
string strSql = "SELECT LastName FROM mytable WHERE LastName IS NOT NULL";
SqlCeConnection mConnection = new SqlCeConnection(connectionString);
SqlCeCommand mCommand = new SqlCeCommand(strSql, mConnection);
PartNumberDataSet = new MyDataBase();
// Read all rows from the table into a dataset
SqlCeDataAdapter PNadapter = new SqlCeDataAdapter(mCommand);
PNadapter.Fill(PartNumberDataSet, "mytable ");
However, I want to minimize amount of data that I will have to store in the memory (I have a lot of 20 or so columns in that table). How can I save this query into some array or collection instead? I only need LastName values.