How to populate dataset using SqlDataReader while stored procedure returns multiple tables?
I am executing a stored procedure in asynchronous mode from codebehind using SqlCommand
's BeginExecuteNonQuery
or BeginExecuteReader
method.
The stored procedure returns multiple tables as there are more than 1 select statement.
I开发者_运维知识库 want to get those tables in a DataSet.
Is it possible?
Please help.
Thanks.
Use a SqlDataAdapter to fill the dataset like this:
SqlConnection conn = new SqlConnection(connection);
SqlDataAdapter adapter = new SqlDataAdapter();
adapter.SelectCommand = new SqlCommand("exec spSomeStoredProc", conn);
adapter.Fill(dataset);
// dataset.Tables[0] - refers to resultset obtained from first SQL query
// in stored procedure. dataset.Tables[1] - refers to resultset obtained
// from second SQL query. Etc.
If it has to be done Async take a look at the code in the following article which shows how to pull back a DataSet asynchronously.
Asynchronous DataSet
精彩评论