Results 1 to 3 of 3
-
10-07-2010, 05:55 PM #1
- Join Date
- Apr 2008
- Location
- Boston, MA
- Posts
- 13,232
- Thanks
- 745
- Thanked 729 Times in 564 Posts
- Blog Entries
- 4
- Feedback Score
- 4 (100%)
How to Get Multiple Tables From Stored Procedure - MS SQL, ASP .NET
How to Get Multiple Tables From Stored Procedure - MS SQL, ASP .NET
Lets say you have a stored procedure that makes multiple select statements to return multiple sets of data. And you like to get them on your Asp .Net code. Take this stored procedure for example:
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: Name
-- Create date:
-- Description:
-- =============================================
CREATE PROCEDURE [dbo].[TestSproc]
AS
BEGIN
SET NOCOUNT ON;
Select top 10 * from MyTable1
Select top 10 * from MyTable2
END
On your Asp .Net you can code like this to retrieve multiple tables from the stored procedure. This code is in C#.
DataTable table1=new DataTable();
DataTable table2=new DataTable();
string connectionString="------------------"; //set the connectionString
System.Data.SqlClient.SqlConnection connection = new System.Data.SqlClient.SqlConnection(connectionStri ng);
connection.Open();
System.Data.SqlClient.SqlCommand command = new System.Data.SqlClient.SqlCommand();
command.Connection = connection;
command.CommandText = "TestSproc";
command.CommandType = CommandType.StoredProcedure;
//set sproc params
SqlDataAdapter adapter = new SqlDataAdapter(command);
DataSet dataSet = new DataSet();
adapter.Fill(dataSet);
if (dataSet.Tables.Count > 0)
table1 = dataSet.Tables[0];
if (dataSet.Tables.Count > 1)
table2 = dataSet.Tables[1];
connection.Close();Free Classified Ads & BUSINESS/PROFESSIONAL SOCIAL NETWORK
-
04-03-2012, 03:01 AM #2
Sophomore
- Join Date
- Mar 2012
- Posts
- 144
- Thanks
- 0
- Thanked 1 Time in 1 Post
- Feedback Score
- 0
i think you get the multitable from the stroed procdure..
-
08-08-2012, 06:00 AM #3
Freshman
- Join Date
- Aug 2012
- Posts
- 12
- Thanks
- 0
- Thanked 0 Times in 0 Posts
- Feedback Score
- 0
ok and thanks for this.....
Similar Threads
-
List of database tables and stored procedures - MS SQL
By manik in forum DatabasesReplies: 0Last Post: 04-22-2010, 07:25 PM -
What is the procedure of submitting your site to dmoz?
By ovaismirza22 in forum General MarketingReplies: 7Last Post: 02-23-2010, 10:48 PM -
perform before retrieving data from the next result set of a stored procedure
By gkumar in forum DatabasesReplies: 2Last Post: 10-26-2009, 08:06 AM -
Article Submission procedure?
By Gensofts in forum Search Engine OptimizationReplies: 18Last Post: 02-04-2009, 04:14 PM -
Google's hiting procedure
By himoacs in forum GoogleReplies: 0Last Post: 07-25-2008, 05:57 PM



Reply With Quote

