Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Stored Procedure Question

Stored Procedure Question

Scheduled Pinned Locked Moved C#
questionsharepointdatabase
7 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    Hum Dum
    wrote on last edited by
    #1

    Create Procedure MultiTable
    As
    Begin
    Select Name, Email from A
    Select X,Y from B
    Select J, K from C
    End

    When We call this Sp return result set in tables as table, table1, table2. Can we give these table name what we want? I mean instead of table, table1 it should give A,B..

    SqlConnection conn = new SqlConnection("Con String");
    SqlDataAdapter da = new SqlDataAdapter("MultiTable",conn);
    da.SelectCommand.CommandType = CommandType.StoredProcedure;

    DataSet ds = new DataSet();
    da.Fill(ds);

    L J 2 Replies Last reply
    0
    • H Hum Dum

      Create Procedure MultiTable
      As
      Begin
      Select Name, Email from A
      Select X,Y from B
      Select J, K from C
      End

      When We call this Sp return result set in tables as table, table1, table2. Can we give these table name what we want? I mean instead of table, table1 it should give A,B..

      SqlConnection conn = new SqlConnection("Con String");
      SqlDataAdapter da = new SqlDataAdapter("MultiTable",conn);
      da.SelectCommand.CommandType = CommandType.StoredProcedure;

      DataSet ds = new DataSet();
      da.Fill(ds);

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      You cannot decide name of the resultset inside the SP. The ADO.NET will give the default name, like first resultset has name "Table", second has "Table1", and so on. HTH

      Jinal Desai - LIVE Experience is mother of sage....

      1 Reply Last reply
      0
      • H Hum Dum

        Create Procedure MultiTable
        As
        Begin
        Select Name, Email from A
        Select X,Y from B
        Select J, K from C
        End

        When We call this Sp return result set in tables as table, table1, table2. Can we give these table name what we want? I mean instead of table, table1 it should give A,B..

        SqlConnection conn = new SqlConnection("Con String");
        SqlDataAdapter da = new SqlDataAdapter("MultiTable",conn);
        da.SelectCommand.CommandType = CommandType.StoredProcedure;

        DataSet ds = new DataSet();
        da.Fill(ds);

        J Offline
        J Offline
        J4amieC
        wrote on last edited by
        #3

        Folloowing on from the above answer, ADO.NET assigns the first resultset the name "Table", the second "Table1", the third "Table2" and so on. Therefore you can map these table names to names of your choosing:

        da.TableMappings.Add("Table","A");
        da.TableMappings.Add("Table1","B");
        da.TableMappings.Add("Table2","C");

        D 1 Reply Last reply
        0
        • J J4amieC

          Folloowing on from the above answer, ADO.NET assigns the first resultset the name "Table", the second "Table1", the third "Table2" and so on. Therefore you can map these table names to names of your choosing:

          da.TableMappings.Add("Table","A");
          da.TableMappings.Add("Table1","B");
          da.TableMappings.Add("Table2","C");

          D Offline
          D Offline
          ddecoy
          wrote on last edited by
          #4

          You could also add the tablenames as out parameters in the stored procedure.

          @Table Text OUTPUT
          ,@Table1 Text OUTPUT
          AS
          

          BEGIN -- SET NOCOUNT ON added to prevent extra result sets from
          -- interfering with SELECT statements.
          SET NOCOUNT ON;
          SET @Table = 'FirstTableName'
          SET @Table1 = 'SecondTableName'
          -- Insert statements for procedure here
          SELECT * FROM A
          SELECT * FROM B

          END

          And in code you just match the tablenames:

          foreach (SqlParameter p in dataAdapter1.SelectCommand.Parameters)
          {
          dataSet1.Tables[p.ParameterName].TableName = (string) p.Value;
          }

          J 1 Reply Last reply
          0
          • D ddecoy

            You could also add the tablenames as out parameters in the stored procedure.

            @Table Text OUTPUT
            ,@Table1 Text OUTPUT
            AS
            

            BEGIN -- SET NOCOUNT ON added to prevent extra result sets from
            -- interfering with SELECT statements.
            SET NOCOUNT ON;
            SET @Table = 'FirstTableName'
            SET @Table1 = 'SecondTableName'
            -- Insert statements for procedure here
            SELECT * FROM A
            SELECT * FROM B

            END

            And in code you just match the tablenames:

            foreach (SqlParameter p in dataAdapter1.SelectCommand.Parameters)
            {
            dataSet1.Tables[p.ParameterName].TableName = (string) p.Value;
            }

            J Offline
            J Offline
            J4amieC
            wrote on last edited by
            #5

            X| You can also bang in a nail with a pair of pliers - doesn't mean its a good idea!

            D 1 Reply Last reply
            0
            • J J4amieC

              X| You can also bang in a nail with a pair of pliers - doesn't mean its a good idea!

              D Offline
              D Offline
              ddecoy
              wrote on last edited by
              #6

              If you only got pliers, than it's a good idea...

              D 1 Reply Last reply
              0
              • D ddecoy

                If you only got pliers, than it's a good idea...

                D Offline
                D Offline
                Dave Kreskowiak
                wrote on last edited by
                #7

                Only if you, or the person who has to maintain your code, don't need to use the pliers later...

                A guide to posting questions on CodeProject[^]
                Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
                     2006, 2007, 2008
                But no longer in 2009...

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups