Results 1 to 3 of 3
  1. #1
    manik's Avatar
    manik is offline Om Shanti!
    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%)

    Default 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


  2. #2
    jassmee is offline Sophomore
    Join Date
    Mar 2012
    Posts
    144
    Thanks
    0
    Thanked 1 Time in 1 Post
    Feedback Score
    0

    Default

    i think you get the multitable from the stroed procdure..

  3. #3
    sandy712 is offline Freshman
    Join Date
    Aug 2012
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Feedback Score
    0

    Default

    ok and thanks for this.....

Similar Threads

  1. Replies: 0
    Last Post: 04-22-2010, 07:25 PM
  2. What is the procedure of submitting your site to dmoz?
    By ovaismirza22 in forum General Marketing
    Replies: 7
    Last Post: 02-23-2010, 10:48 PM
  3. Replies: 2
    Last Post: 10-26-2009, 08:06 AM
  4. Article Submission procedure?
    By Gensofts in forum Search Engine Optimization
    Replies: 18
    Last Post: 02-04-2009, 04:14 PM
  5. Google's hiting procedure
    By himoacs in forum Google
    Replies: 0
    Last Post: 07-25-2008, 05:57 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Partners: BOSTON WEB DEVELOPER, LLC   |   WEBCOSMO CLASSIFIEDS