如何处理多个结果集,每个结果集有多行? IDataReader.NextResult() 结束 Read()
如何处理多个结果集,每个结果集有多行? 对 NextResult()
的调用会中断 while 循环。
我的一些 SP 返回多个结果集。我使用 NextResult()
处理这些,但是当我这样做并且我的 SP 只有一个 ResultSet 时,我看到带有 Read() 的 while 循环完成后只剩下第一行。
如果不调用 NextResult()
我会获取第一个 ResultSet 的所有行,但当然第二个和后续 ResultSet 不会得到处理?
using (IDataReader reader = storedProcedure.ExecuteReader(
CommandBehavior.CloseConnection, parameterNames as string[], arguments))
{
while (reader.Read())
{
ArrayList row = new ArrayList();
for (int j = 0; j < reader.FieldCount; ++j)
{
object rowValue = reader.GetValue(j);
row.Add(rowValue);
}
reader.NextResult();//next resultset, breaks out of the while
}
}
How to handle multiple ResultSets, each with multiple Rows?
The call to NextResult()
breaks the while loop.
Some of my SPs return multiple ResultSets. I'm handling these with NextResult()
but when I do and my SP only has a single ResultSet, I see the while loop with Read() finishes leaving me with only the first Row.
Without the call to NextResult()
I get all the rows for the first ResultSet but of course the second and subsequent ResultSets don't get processed?
using (IDataReader reader = storedProcedure.ExecuteReader(
CommandBehavior.CloseConnection, parameterNames as string[], arguments))
{
while (reader.Read())
{
ArrayList row = new ArrayList();
for (int j = 0; j < reader.FieldCount; ++j)
{
object rowValue = reader.GetValue(j);
row.Add(rowValue);
}
reader.NextResult();//next resultset, breaks out of the while
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要创建两个嵌套循环。
NextResult
Read
。像这样的东西:
You need to create two nested loops.
NextResult
at the endRead
at the beginning.Something like: