I\'m trying to fill DataSet which contains 2 tables with one to many relationship. I\'m using DataReader to achieve this :
public DataSet SelectOne(int i
Here is very good answer of your question
see the example mentioned on above MSDN page :-
Method Load
of DataTable
executes NextResult
on the DataReader
, so you shouldn't call NextResult
explicitly when using Load
, otherwise odd tables in the sequence would be omitted.
Here is a generic solution to load multiple tables using a DataReader
.
// your command initialization code here
// ...
DataSet ds = new DataSet();
DataTable t;
using (DbDataReader reader = command.ExecuteReader())
{
while (!reader.IsClosed)
{
t = new DataTable();
t.Load(rs);
ds.Tables.Add(t);
}
}