Creating a multi table select stored procedure

  • Thread starter Thread starter Karl
  • Start date Start date
K

Karl

Am in the process of learning to use C#.

Need to create a stored procedure that returns a dataSet
containing several tables and then access this query from
an object.
 
Hey Karl

All you need to do is create a stored procedure that has a bunch of select statements in i

CREATE PROCEDURE usp_GetSomeStuf
A
SELECT * FROM Table
SELECT * FROM Table
SELECT * FROM Table

The following code will allow you to access each table

SqlConnection myConnection = new SqlConnection ({ConnectString})
myConnection.Open()
SqlCommand command = new SqlCommand("usp_GetSomeStuff", myConnection)
DataSet ds = new DataSet()
SqlAdapter adapter = new SqlAdapter(command)
adapter.fill(ds)

ds.Tables[0] now references your first select, ds.Tables[1] references your second select, etc.
 
HI Karl,
How about the performance will affect if you run
different stored procedures for each select statemnt
instead of group which one is better.
Thanks
suda
-----Original Message-----
Hey Karl,

All you need to do is create a stored procedure that has
a bunch of select statements in it
CREATE PROCEDURE usp_GetSomeStuff
AS
SELECT * FROM Table1
SELECT * FROM Table2
SELECT * FROM Table3

The following code will allow you to access each table:

SqlConnection myConnection = new SqlConnection ({ConnectString});
myConnection.Open();
SqlCommand command = new SqlCommand("usp_GetSomeStuff", myConnection);
DataSet ds = new DataSet();
SqlAdapter adapter = new SqlAdapter(command);
adapter.fill(ds);

ds.Tables[0] now references your first select, ds.Tables
[1] references your second select, etc.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top