以前很少用到,今天突然有一个存储过程返回的是两个数据集,我原来的执行方式如下:
public static DataView RetrunProc(string Proc_Name,SqlParameter[] Para)
{
int i;
SqlConnection myCn = new SqlConnection(strConn);
SqlDataAdapter MyCmd = new SqlDataAdapter(Proc_Name,myCn);
try
{
myCn.Open();
MyCmd.SelectCommand.CommandType=CommandType.StoredProcedure;
for(i=0;i<Para.Length;i++)
{
MyCmd.SelectCommand.Parameters.Add(Para[i]);
![](/Images/OutliningIndicators/InBlock.gif)
}
DataSet Myds = new DataSet();
MyCmd.Fill(Myds,"table");
return Myds.Tables["table"].DefaultView;
}
catch(System.Data.SqlClient.SqlException e)
{
throw new Exception(e.Message);
}
finally
{
MyCmd.Dispose();
myCn.Close();
}
}这样是没有办法得到第二个数据集的,修改如下
/// <summary>
/// 调用存储过程并报回DataSet
/// </summary>
/// <param name="Proc_Name"></param>
/// <param name="Para"></param>
/// <returns></returns>
public static DataSet RunProcForSet(string Proc_Name,SqlParameter[] Para)
{
int i;
SqlConnection myCn = new SqlConnection(strConn);
SqlDataAdapter MyCmd = new SqlDataAdapter(Proc_Name,myCn);
try
{
myCn.Open();
MyCmd.SelectCommand.CommandType=CommandType.StoredProcedure;
for(i=0;i<Para.Length;i++)
{
MyCmd.SelectCommand.Parameters.Add(Para[i]);
}
DataSet Myds = new DataSet();
MyCmd.Fill(Myds);
return Myds;
}
catch(System.Data.SqlClient.SqlException e)
{
throw new Exception(e.Message);
}
finally
{
MyCmd.Dispose();
myCn.Close();
}
}
这样就可以通过MyDs.Tables[0],MyDs.Tables[1]等方式访问返回的多个数据集了.
另外,还有一种通过Adapter的方式,我没有测试.
不过,目前有另外一种需求不知道如何解决,就是在存储过程中的print的内容,程序中有没有办法接收到呢?
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](/Images/OutliningIndicators/ExpandedBlockEnd.gif)
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ExpandedBlockEnd.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](/Images/OutliningIndicators/ExpandedBlockEnd.gif)
这样就可以通过MyDs.Tables[0],MyDs.Tables[1]等方式访问返回的多个数据集了.
另外,还有一种通过Adapter的方式,我没有测试.
不过,目前有另外一种需求不知道如何解决,就是在存储过程中的print的内容,程序中有没有办法接收到呢?