How can I make a function that returns dynamic List<>

  • Thread starter Thread starter Mr. X.
  • Start date Start date
M

Mr. X.

I want to make a query, and translate it to list.
I don't know how many columns will be return at the selected result,
so the list can contain 100 columns or 5 columns.

I need an example how to do so, please.

Thanks :)
 
I want to make a query, and translate it to list.
I don't know how many columns will be return at the selected result, so
the list can contain 100 columns or 5 columns.

I need an example how to do so, please.

You can store data as List<List<object>>.

Code outline:

List<List<object>> tbl = new List<List<object>>();
IDataReader rdr = cmd.ExecuteReader();
while(rdr.Read())
{
List<object> row = new List<object>();
for(int i = 0; i < rdr.FieldCount; i++)
{
row.Add(rdr);
}
tbl.Add(row);
}

But my recommendation would be to reconsider the data
structure and pick something a little bit more
type safe.

Arne
 
Back
Top