Solved

Dataset filled with two Stored Procedures

Posted on 2012-03-26
14
330 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
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
 

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
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
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…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

707 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now