Returning multiple tables from a stored procedure and dataset

hi
i need show tow table in my procedure  
but when get dataset wizard and select procedure  show only first table how to get next result to datagridview  
project in attach
dataset1.png
dataset2.png
dataset3.png
dataset4.png
dataset-test.zip
mahmuodAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ste5anSenior DeveloperCommented:
This depends on how you access the data in C#.

When you use a SqlDataReader then it's quite simple: Use the NextResult() method. E.g. Retrieving Data Using a DataReader.
0
mahmuodAuthor Commented:
i am used Designer
DataSet1.Designer.cs
DataSet1.xsd
how to alter in DataSet1.Designer.cs code.

i cant use  NextResult() method.
0
mahmuodAuthor Commented:
Jim Horn- ican not alter after Comment u can alter .
0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Mike EghtebasDatabase and Application DeveloperCommented:
Make two stored procedures. One per table.

Mike
0
mahmuodAuthor Commented:
eghtebas- i know tow procedures but this just example. because i have other procedures hvae #table and more work
and return more table
0
Mike EghtebasDatabase and Application DeveloperCommented:
Mahmuod,

It seems, "you can’t access its second result set. The solution is to render same data as XML and return this XML as output parameter."

You have something like this:
create procedure GetBlogWithDetails(@BlogId int) as 
begin
select BlogId, BlogName 
  from Blog 
  where BlogId = @BlogId

  select PostId, BlogId, PostName 
  from Post 
  where BlogId = @BlogId
end

Open in new window

But, it has to be like this:
create procedure GetBlogWithDetailsXml(
  @blogId int, 
  @xml xml output) as 
begin
  -- first, create 2 table variables for blogs and for posts
  declare @blogRows table(BlogId int, BlogName nvarchar(256))
  declare @postRows table(PostId int, BlogId int, PostName nvarchar(256))

  -- (#1) this is where you implement your useful logic
  insert into @blogRows
  select BlogId, BlogName 
  from Blog 
  where BlogId = @blogId

  insert into @postRows
  select PostId, BlogId, PostName 
  from Post
  where BlogId = @blogId

  -- here you render your 2 tables containing useful data as XML
  declare @blogRowsXml xml = (
    select BlogId, BlogName 
    from @blogRows as Blog
    for xml auto)

  declare @postRowsXml xml = (
    select PostId, BlogId, PostName 
    from @postRows as Post
    for xml auto)

  -- here you build a single XML with all the data required
  set @xml = 
    cast(@blogRowsXml as nvarchar(max)) + 
    cast(@postRowsXml as nvarchar(max))

  -- (#2) here you return the data as "raw" result sets.
  select * from @blogRows
  select * from @postRows
end

Open in new window

There may be other ways to go about. But see if you can make it work using XML which works in T-SQL environment as well. For more see: www.codeproject.com/Articles/620635/Stored-procedures-and-multiple-result-sets-in-T-SQ

Return:
declare @xml xml
exec GetBlogWithDetailsXml 1, @xml output
select @xml

Open in new window

Mike
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.