开发者

How to populate dataset using SqlDataReader while stored procedure returns multiple tables?

开发者 https://www.devze.com 2023-01-12 15:21 出处:网络
I am executing a stored procedure in asynchronous mode from codebehind using SqlCommand\'s BeginExecuteNonQuery or BeginExecuteReader method.

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

0

精彩评论

暂无评论...
验证码 换一张
取 消