SQLDataReader 未读取存储过程返回的第二个 table
SQLDataReader is not reading the second table returned by stored procedure
我正在使用以下代码使用 DataReader 读取和填充两个 C# 对象。但是我无法阅读第二个 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();
}
下面是SP返回的数据片段
DataTable.Load
已经推进了 reader,最后 - 本质上:
if (!reader.IsClosed && !reader.NextResult())
{
reader.Close();
}
(citation from reference source)
所以:在使用Load
时不要自己调用NextResult
,那样会导致第二个格子被跳过。
我正在使用以下代码使用 DataReader 读取和填充两个 C# 对象。但是我无法阅读第二个 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();
}
下面是SP返回的数据片段
DataTable.Load
已经推进了 reader,最后 - 本质上:
if (!reader.IsClosed && !reader.NextResult())
{
reader.Close();
}
(citation from reference source)
所以:在使用Load
时不要自己调用NextResult
,那样会导致第二个格子被跳过。