我正在使用以下代码使用datareader读取并填充两个C#对象。但我看不到第二张桌子。
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();
}
下面是SP返回的数据片段
[DataTable.Load
]已经使阅读器进步了,基本上是:
if (!reader.IsClosed && !reader.NextResult())
{
reader.Close();
}
(citation from reference source)
所以:在使用NextResult
时不要自己叫Load
,因为那样会导致第二个网格被跳过。