How would I store results from dataset in an Ilist?
Model read = new Model()
IList<sqlprop> sqlprop= read.readrows("SELECT * FROM test").Tables[0].Cast<DataRow>().ToList();
Class Model
{
public DataSet readrows(string query)
{
............
return dataset;
}
}
Class sqlprop
{
string data1 get;set;
string data2 get;set;
.........
}
Something like this would do what you want I think…
You should check for DBNull.Value and probably include the column name in the SQL query etc, etc, but you get the idea.
Update
If you need it to be generic and the column name in the database exactly matches the property name you could do something like this (untested, I have no compiler here but it should give you the idea):
NOTE: This is a bit flaky and not super efficient but anyway, there it is!