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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Database & SysAdmin
  3. Database
  4. Multiple queries in a stored procedure

Multiple queries in a stored procedure

Scheduled Pinned Locked Moved Database
csharpdatabasequestion
6 Posts 4 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.
  • A Offline
    A Offline
    Ahamed Azeem
    wrote on last edited by
    #1

    Hi Gents, I have used two select queries in a stored procedure.. how can i retrieve the values from the two queries in a single datareader for ex, set ANSI_NULLS ON set QUOTED_IDENTIFIER ON go ALTER Procedure [dbo].[SearchDoctor] @fname varchar(50), @lname varchar(50) As Select * from docregistration where fname=@fname and lname=@lname Declare @Speciality varchar(50) Select @Speciality=Speciality from docregistration where fname=@fname and lname=@lname Select Speciality from Speciality where SpecialityID=@Speciality GO Thanks a lot in advance Azeem, Senior Dotnet Developer

    T W 2 Replies Last reply
    0
    • A Ahamed Azeem

      Hi Gents, I have used two select queries in a stored procedure.. how can i retrieve the values from the two queries in a single datareader for ex, set ANSI_NULLS ON set QUOTED_IDENTIFIER ON go ALTER Procedure [dbo].[SearchDoctor] @fname varchar(50), @lname varchar(50) As Select * from docregistration where fname=@fname and lname=@lname Declare @Speciality varchar(50) Select @Speciality=Speciality from docregistration where fname=@fname and lname=@lname Select Speciality from Speciality where SpecialityID=@Speciality GO Thanks a lot in advance Azeem, Senior Dotnet Developer

      T Offline
      T Offline
      The Man from U N C L E
      wrote on last edited by
      #2

      You can't. A DataReader itterates through a set of rows from a single result table. What you need to use is a DataAdaptor with a dataset. Eg.

      System.Data.DataSet myDS = new System.Data.DataSet();
      System.Data.SqlClient.SqlDataAdapter myAdaptor
      = new System.Data.SqlClient.SqlDataAdapter("Execute myProcedure;"
      ,new System.Data.SqlClient.SqlConnection(myConnectionString));
      myAdaptor.Fill(myDS)

      If you have knowledge, let others light their candles at it. Margaret Fuller (1810 - 1850) www.JacksonSoft.co.uk

      A 1 Reply Last reply
      0
      • A Ahamed Azeem

        Hi Gents, I have used two select queries in a stored procedure.. how can i retrieve the values from the two queries in a single datareader for ex, set ANSI_NULLS ON set QUOTED_IDENTIFIER ON go ALTER Procedure [dbo].[SearchDoctor] @fname varchar(50), @lname varchar(50) As Select * from docregistration where fname=@fname and lname=@lname Declare @Speciality varchar(50) Select @Speciality=Speciality from docregistration where fname=@fname and lname=@lname Select Speciality from Speciality where SpecialityID=@Speciality GO Thanks a lot in advance Azeem, Senior Dotnet Developer

        W Offline
        W Offline
        WoutL
        wrote on last edited by
        #3

        Execute DataReader.NextResult() should do the trick.

        Wout Louwers

        1 Reply Last reply
        0
        • T The Man from U N C L E

          You can't. A DataReader itterates through a set of rows from a single result table. What you need to use is a DataAdaptor with a dataset. Eg.

          System.Data.DataSet myDS = new System.Data.DataSet();
          System.Data.SqlClient.SqlDataAdapter myAdaptor
          = new System.Data.SqlClient.SqlDataAdapter("Execute myProcedure;"
          ,new System.Data.SqlClient.SqlConnection(myConnectionString));
          myAdaptor.Fill(myDS)

          If you have knowledge, let others light their candles at it. Margaret Fuller (1810 - 1850) www.JacksonSoft.co.uk

          A Offline
          A Offline
          Ashfield
          wrote on last edited by
          #4

          The Man from U.N.C.L.E. wrote:

          You can't.

          Beg to differ. Dataset.Nextresult does it (may have syntax slightly wrong, its not strictly a sql question and I don't have visual studio on this machine)

          Bob Ashfield Consultants Ltd Proud to be a 2009 Code Project MVP

          T 1 Reply Last reply
          0
          • A Ashfield

            The Man from U.N.C.L.E. wrote:

            You can't.

            Beg to differ. Dataset.Nextresult does it (may have syntax slightly wrong, its not strictly a sql question and I don't have visual studio on this machine)

            Bob Ashfield Consultants Ltd Proud to be a 2009 Code Project MVP

            T Offline
            T Offline
            The Man from U N C L E
            wrote on last edited by
            #5

            Good point. I have forgotten that method (on the DataReader actualy), as I tend to use DataReaders for single recordsets and dataadaptor.Fill for multiple record sets.

            If you have knowledge, let others light their candles at it. Margaret Fuller (1810 - 1850) www.JacksonSoft.co.uk

            A 1 Reply Last reply
            0
            • T The Man from U N C L E

              Good point. I have forgotten that method (on the DataReader actualy), as I tend to use DataReaders for single recordsets and dataadaptor.Fill for multiple record sets.

              If you have knowledge, let others light their candles at it. Margaret Fuller (1810 - 1850) www.JacksonSoft.co.uk

              A Offline
              A Offline
              Ashfield
              wrote on last edited by
              #6

              So do I as a rule, but I remembered it from before ADO.NET, when theree were no such things as datasets. Also useful as datareaders are faster than datasets.

              Bob Ashfield Consultants Ltd Proud to be a 2009 Code Project MVP

              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