As the questions says, I'm trying to save the result of a select statement from a SqlDataReader
to a list at once, rather than one by one giving the column name.
Before that I've tried using reader.read()
and then giving the column name one by one and saving the data something like this,
while (reader.Read())
{
label.text = (string) reader["myColumn"];
//..... and so on repeating for all the columns in the DB.
}
Yet I've tried using IDataRecord
to put all the row values in the list but it gives me NULL.
if (reader.HasRows)
{
List<string> list = (from IDataRecord r in reader
select (string)r["FieldName"]).ToList();
}
But this returns a NULL. Anyone can redirect me to proper piece of information will highly be regarded.