J
James K.
I have a single SqlCommand that returns 2 SqlDataReaders - something
like this:
SELECT TOP 100 * from Table1
SELECT TOP 100 * from Table2
I want to get these two SqlDataReaders into two separate DataTables
for output later. (This is just an example; the SqlCommand can return
any number of SqlDataReaders.)
My code (slightly simplified) looks like this:
<SNIP>
reader = commandRunningSql.ExecuteReader(CommandBehavior.Default);
while (reader.FieldCount > 0)
{
dataTable = new DataTable();
// code for this is below
minimalDbDataAdapter.FillFromReader(dataTable, reader);
if (dataTable.Rows.Count > 0)
{
// this binds the dataTable to a dataGrid and
// saves the datagrid for later.
ShowDataTable(dataTable);
}
reader.NextResult(); // this is always false
}
reader.Close();
</SNIP>
And here is the pertinent DbDataAdapter code:
<SNIP>
public class MinimalDbDataAdapter : DbDataAdapter
{
public int FillFromReader(System.Data.DataTable dataTable,
System.Data.IDataReader dataReader)
{
// here is the problem; see comments below
return base.Fill(dataTable, dataReader);
}
// other methods omitted.
}
</SNIP>
The problem appears to be that DbDataAdapter.Fill calls
DbDataAdapter.FillNextResult which in turn calls
SqlDataReader.NextResult. This causes all the SqlDataReaders to be
filled into just one DataTable. I would like my
MinimalDbDataAdapter.FillFromReader function to fill the DataTable
with just the first SqlDataReader and let me call reader.NextResult
later.
Is there a way?
Thanks,
James
like this:
SELECT TOP 100 * from Table1
SELECT TOP 100 * from Table2
I want to get these two SqlDataReaders into two separate DataTables
for output later. (This is just an example; the SqlCommand can return
any number of SqlDataReaders.)
My code (slightly simplified) looks like this:
<SNIP>
reader = commandRunningSql.ExecuteReader(CommandBehavior.Default);
while (reader.FieldCount > 0)
{
dataTable = new DataTable();
// code for this is below
minimalDbDataAdapter.FillFromReader(dataTable, reader);
if (dataTable.Rows.Count > 0)
{
// this binds the dataTable to a dataGrid and
// saves the datagrid for later.
ShowDataTable(dataTable);
}
reader.NextResult(); // this is always false
}
reader.Close();
</SNIP>
And here is the pertinent DbDataAdapter code:
<SNIP>
public class MinimalDbDataAdapter : DbDataAdapter
{
public int FillFromReader(System.Data.DataTable dataTable,
System.Data.IDataReader dataReader)
{
// here is the problem; see comments below
return base.Fill(dataTable, dataReader);
}
// other methods omitted.
}
</SNIP>
The problem appears to be that DbDataAdapter.Fill calls
DbDataAdapter.FillNextResult which in turn calls
SqlDataReader.NextResult. This causes all the SqlDataReaders to be
filled into just one DataTable. I would like my
MinimalDbDataAdapter.FillFromReader function to fill the DataTable
with just the first SqlDataReader and let me call reader.NextResult
later.
Is there a way?
Thanks,
James