简体   繁体   中英

How to get Values from Stored procedure when procedure has two select statements

see i have stored procedure which contain two select statement , please tell me how can i get two result set from single stored procedure. Here is code ---

create proc spReturnsDataFromTwoTable

As

Begin

select * from TableOne

select * from TableTwo

End

Here is a way you can access yours two tables using data adapter:

SqlConnection sqlConn = new SqlConnection("ConnectionString");
  SqlCommand sqlCmd = new SqlCommand("procedureName", sqlConn);
  sqlCmd.CommandType = CommandType.StoredProcedure;
  sqlConn.Open();
  SqlDataAdapter sda = new SqlDataAdapter(sqlCmd);
  DataSet ds = new DataSet();
  sda.Fill(ds);
  sqlconn.Close();

  // Retrieving yours stored tables from a DataSet.
  DataTable dt1 = ds.Tables[0];
  DataTable dt2 = ds.Tables[1];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM