I am using the below code to read and populate two C# objects using datareader. But I am unable to read the second table.
using (var myConnection = new SqlConnection(ConnectionString))
{
var sqlCommand = "usp_GetFileListforPurging";
var cmd = new SqlCommand(sqlCommand, myConnection) { CommandType = CommandType.StoredProcedure };
cmd.CommandTimeout = Timeout == 0 ? 30 : Timeout * 30;
myConnection.Open();
using (var reader = cmd.ExecuteReader())
{
_tableAllSet.Load(reader); //read's the first table
reader.NextResult(); //But this is returning false, although my SP is returning two tables
_tableTrueSet.Load(reader);
}
myConnection.Close();
}
Below is the snip of data returned by SP
DataTable.Load
already progresses the reader, at the end - essentially:
if (!reader.IsClosed && !reader.NextResult())
{
reader.Close();
}
( citation from reference source )
So: don't call NextResult
yourself when using Load
, as that will cause the second grid to be skipped.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.