Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Stored Procedure Multiple Tables

Reply
Thread Tools

Stored Procedure Multiple Tables

 
 
Chris
Guest
Posts: n/a
 
      07-01-2007
This might be a stupid question.... I have a stored procedures, which uses
two selects. When I run the SP I get two resultsets, one very big and the
other much smaller, which is the one I want in the dataset. How do a ensure
only the last one goes in the dataset.


 
Reply With Quote
 
 
 
 
Mark Rae
Guest
Posts: n/a
 
      07-01-2007
"Chris" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...

> This might be a stupid question.... I have a stored procedure, which uses
> two selects. When I run the SP I get two resultsets, one very big and the
> other much smaller, which is the one I want in the dataset. How do a
> ensure only the last one goes in the dataset.


Well, firstly do you need the SP to return both resultsets? If not, get rid
of the one you don't need...

If you do, ignore the one you don't need in the DataSet.

E.g., if you are trying to bind the smaller of the two resultsets into a
GridView, you could do something like this:

DataSet MyDS = <run your SP>;
MyGridView.DataSource = MyDS.Tables[1];
MyGridView.DataBind();


--
http://www.markrae.net

 
Reply With Quote
 
 
 
 
=?Utf-8?B?U2l2YWt1bWFyIEc=?=
Guest
Posts: n/a
 
      07-01-2007
To Add to what Mark has suggested, use an extra parameter to the Stored
procedure whether to do the first select statement using a T-Sql if
condition. If we do so we can avoid populating the dataset with unwanted
data. Binding to the Gridview would now be as follows as we would expect only
one resultset from the stored proc:

DataSet MyDS = <run your SP>;
MyGridView.DataSource = MyDS.Tables[0];
MyGridView.DataBind();

HTH
Siva


"Mark Rae" wrote:

> "Chris" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>
> > This might be a stupid question.... I have a stored procedure, which uses
> > two selects. When I run the SP I get two resultsets, one very big and the
> > other much smaller, which is the one I want in the dataset. How do a
> > ensure only the last one goes in the dataset.

>
> Well, firstly do you need the SP to return both resultsets? If not, get rid
> of the one you don't need...
>
> If you do, ignore the one you don't need in the DataSet.
>
> E.g., if you are trying to bind the smaller of the two resultsets into a
> GridView, you could do something like this:
>
> DataSet MyDS = <run your SP>;
> MyGridView.DataSource = MyDS.Tables[1];
> MyGridView.DataBind();
>
>
> --
> http://www.markrae.net
>
>

 
Reply With Quote
 
sloan
Guest
Posts: n/a
 
      07-03-2007


My suggestion (which is a alternate of the flag being sent is ) is:


Create 2 procedures.


uspEmployeeGetAll
Select EmpID, LastName, FirstName from dbo.Employee


uspDepartmentGetAll
Select DeptID, DepartmentName from dbo.Department

Then a wrapper usp


uspEmployeesAndDepartmentsGetAll
EXEC dbo.uspEmployeeGetAll
EXEC dbo.uspDepartmentGetAll



That'll work.


If you use an IDataReader, you have more control over loading data. But you
pay for it with more code.

See my blog for an example:
http://sholliday.spaces.live.com/Blog/cns!A68482B9628A842A!140.entry



"Chris" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> This might be a stupid question.... I have a stored procedures, which uses
> two selects. When I run the SP I get two resultsets, one very big and the
> other much smaller, which is the one I want in the dataset. How do a

ensure
> only the last one goes in the dataset.
>
>



 
Reply With Quote
 
Rad [Visual C# MVP]
Guest
Posts: n/a
 
      07-03-2007
Mark Rae wrote:
> "Chris" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>
>> This might be a stupid question.... I have a stored procedure, which
>> uses two selects. When I run the SP I get two resultsets, one very big
>> and the other much smaller, which is the one I want in the dataset.
>> How do a ensure only the last one goes in the dataset.

>
> Well, firstly do you need the SP to return both resultsets? If not, get
> rid of the one you don't need...
>
> If you do, ignore the one you don't need in the DataSet.
>
> E.g., if you are trying to bind the smaller of the two resultsets into a
> GridView, you could do something like this:
>
> DataSet MyDS = <run your SP>;
> MyGridView.DataSource = MyDS.Tables[1];
> MyGridView.DataBind();
>
>

An additional benefit of doing this is that it will even run faster!

--
http://bytes.thinkersroom.com
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Using a stored procedure to return multiple recordsets with .Filter support stjulian ASP General 1 11-01-2006 04:27 PM
'Procedure or function <stored procedure name> has too many arguments specified',,,ARGH! Mike P ASP .Net 0 06-19-2006 01:19 PM
updating multiple rows in MS SQL by way of calling stored procedure takes forever Lex Java 3 12-30-2005 02:15 PM
getting multiple table results question using stored procedure Patrick Olurotimi Ige ASP .Net 2 05-09-2005 10:57 AM
Multiple recordset from a stored procedure Jon Spivey ASP .Net 3 02-01-2004 04:43 PM



Advertisments