如何使用executeReader在sp中检索第二个选择查询 [英] How to retrieve second select query in sp with executeReader

查看:75
本文介绍了如何使用executeReader在sp中检索第二个选择查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好

我的存储过程包含两个过程.
说选择Query1并选择query2.
我想使用Execute Reader检索第二个选择查询.
在sql server中有可能吗?

谁能帮我



问候
Froxy

Hi All

I have stored procedure which contains two procedures.
Say select Query1 and select query2.
I want to retrieve the second select query with Execute Reader.
Is that possible in sql server.

Can anyone help me



Regards
Froxy

推荐答案



您可以在SqlCommand上执行NextResult来提高Reader的功能.

Hi,

you can perform NextResult on your SqlCommand to advance your Reader.

var result = sqlCommand.ExecuteReader();
if (result.NextResult())
{ 
// "result" variable contain next query resultset from DataSet
}



希望对您有帮助,

谢谢
-Amit.



hope this will help you,

thanks
-Amit.


亲爱的Froxy,

您只需要这样做:-

Dear Froxy,

You just have to do this:-

    SqlConnection nwindConn = new SqlConnection("Data Source=localhost;Integrated Security=SSPI;Initial Catalog=northwind");

SqlCommand salesCMD = new SqlCommand("SalesByCategory", nwindConn);
salesCMD.CommandType = CommandType.StoredProcedure;

SqlParameter myParm = salesCMD.Parameters.Add("@CategoryName", SqlDbType.NVarChar, 15);
myParm.Value = "Beverages";

nwindConn.Open();

SqlDataReader myReader = salesCMD.ExecuteReader().Table[1];

Console.WriteLine("{0}, {1}", myReader.GetName(0), myReader.GetName(1));

while (myReader.Read())
{
  Console.WriteLine("{0},


{1}", myReader.GetString(0), myReader.GetDecimal(1)); } myReader.Close(); nwindConn.Close();
{1}", myReader.GetString(0), myReader.GetDecimal(1)); } myReader.Close(); nwindConn.Close();



希望对您有所帮助

谢谢



I hope this will help you out

Thanks


这篇关于如何使用executeReader在sp中检索第二个选择查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆