Solved

Dataset filled with two Stored Procedures

Posted on 2012-03-26
14
337 Views
Last Modified: 2012-03-28
I would like to have two Stored Procedures data brought together into a single Dataset, how do I do this? One of the SP requires a Parameter value.

Please provide a typical ASP.NET / ADO.NET / SQL Server example.
0
Comment
Question by:mitdaniels
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
14 Comments
 
LVL 21

Expert Comment

by:Dale Burrell
ID: 37765175
Tricky... any chance you can change them into table valued functions?
0
 
LVL 18

Expert Comment

by:DarrenD
ID: 37765188
Hi,

If you have the same number of columns in each query then you cold use a UNION statement in SQL


http://www.w3schools.com/sql/sql_union.asp

http://www.techonthenet.com/sql/union.php

There are many references on the web if you do a quick search for SQL Union

Cheers,

Darren
0
 
LVL 12

Expert Comment

by:Anuradha Goli
ID: 37765277
Retrieve the data from tables in 2 queries and then UNION them in stored procedure in SQL Server.

In Visual Studio ,attach the dataset to grid in asp.net using ADO.Net

http://asmaqureshi.blogspot.com/2010/01/fill-dataset-with-storedprocedure.html
0
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 

Author Comment

by:mitdaniels
ID: 37766665
Thanks for the input experts.

The one Stored Procedure does JOINS on numerous tables, and the problem lies with not being able to JOIN one table, which only has two columns, while the JOINED SP has many more columns, so a UNION is perhaps unlikely??
0
 
LVL 18

Expert Comment

by:DarrenD
ID: 37766680
Hi,

I think you might have to put up an example of the data so that we can see what we have to work with.

Cheers,

Darren
0
 

Author Comment

by:mitdaniels
ID: 37766929
Unfortunately a good example will take too much time to put together and explain.
0
 

Author Comment

by:mitdaniels
ID: 37766967
Thus far I've heard nothing from the Dataset or ADO.NET gurus, perhaps the solution lies there??
0
 
LVL 18

Assisted Solution

by:DarrenD
DarrenD earned 500 total points
ID: 37770489
0
 

Author Comment

by:mitdaniels
ID: 37771890
Thanks, that looks like it might work if I can pull certain columns out to make two DataTables that have the same schema, can that be done? What is the step before the DataTable?
0
 
LVL 18

Assisted Solution

by:DarrenD
DarrenD earned 500 total points
ID: 37772228
Hi,

You will have to create the schemas for the two data tables. I'm not sure I understand the Question "What is the step before the DataTable?"

1. Get the data from the 1st stored procedure into a datatable and load it into your schema using the columns you need.

2. Get the data from the 2nd stored procedure into a datatable

3. Merge the datatables

From the 1st link that I sent it appears possible to merge tables that do not have the same schema which is what you were basically talking about in your original post where you spoke of two different stored procedures with different numbers of columns.

Cheers,

Darren
0
 

Author Comment

by:mitdaniels
ID: 37772479
Thanks Darren,

The step before the DataTable is it getting the Dataset, or is it possible to use an existing Datareader, this might be a silly question, since I am not really sure how these Dataset features all work together, and  what relationship they have with the DataReader in this instance.

For some reason I get the impression that the DataTable can be used independently of any Dataset, but that might not be so.
0
 
LVL 18

Accepted Solution

by:
DarrenD earned 500 total points
ID: 37775600
Hi again,

A DataSet can contain many DataTables, just like a database and also allows you to add relations between DataTables in the DataSet. So you could have order and customer tables and then link them together using a foregin key like order.orderid = customer.orderid

This shows you how to load a DataTable using a DataReader.
http://imar.spaanjaars.com/406/filling-a-datatable-or-dataset-the-quick-way

http://msdn.microsoft.com/en-us/library/ms171920%28v=vs.80%29.aspx

Hope this helps,

Darren
0
 

Author Comment

by:mitdaniels
ID: 37777284
I think those are the missing pieces, will give it a go today, thanks.
0
 

Author Closing Comment

by:mitdaniels
ID: 37777924
I think you've put me on a path to a solution.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
For most people, the WrapPanel seems like a magic when they switch from WinForms to WPF. Most of us will think that the code that is used to write a control like that would be difficult. However, most of the work is done by the WPF engine, and the W…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question