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. Web Development
  3. ASP.NET
  4. Multiple Select Statements in DataAdapter

Multiple Select Statements in DataAdapter

Scheduled Pinned Locked Moved ASP.NET
helptutorialquestion
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.
  • V Offline
    V Offline
    VanithaVasu
    wrote on last edited by
    #1

    Can i write Multiple Select Statements in DataAdapter . If it is Possible means How to write ? I have written like this but it is throwing the error. DataAdapter=new OleDbDataAdapter("select * from Table1;select * from Table2",connection);

    VanithaVasu

    S N 2 Replies Last reply
    0
    • V VanithaVasu

      Can i write Multiple Select Statements in DataAdapter . If it is Possible means How to write ? I have written like this but it is throwing the error. DataAdapter=new OleDbDataAdapter("select * from Table1;select * from Table2",connection);

      VanithaVasu

      S Offline
      S Offline
      S A R I T H
      wrote on last edited by
      #2

      No u canot write like this.. u can use join querry

      Sarith...

      1 Reply Last reply
      0
      • V VanithaVasu

        Can i write Multiple Select Statements in DataAdapter . If it is Possible means How to write ? I have written like this but it is throwing the error. DataAdapter=new OleDbDataAdapter("select * from Table1;select * from Table2",connection);

        VanithaVasu

        N Offline
        N Offline
        N a v a n e e t h
        wrote on last edited by
        #3

        VanithaVasu wrote:

        Can i write Multiple Select Statements in DataAdapter .

        Yes you can. When you fill dataset, it will contain two datatables. But instead of separating multiple queries with ; symbol, it's better to go for store procedure's.

        VanithaVasu wrote:

        I have written like this but it is throwing the error. DataAdapter=new OleDbDataAdapter("select * from Table1;select * from Table2",connection);

        What's the error it's throwing ?


        My Website | Ask smart questions

        V 1 Reply Last reply
        0
        • N N a v a n e e t h

          VanithaVasu wrote:

          Can i write Multiple Select Statements in DataAdapter .

          Yes you can. When you fill dataset, it will contain two datatables. But instead of separating multiple queries with ; symbol, it's better to go for store procedure's.

          VanithaVasu wrote:

          I have written like this but it is throwing the error. DataAdapter=new OleDbDataAdapter("select * from Table1;select * from Table2",connection);

          What's the error it's throwing ?


          My Website | Ask smart questions

          V Offline
          V Offline
          VanithaVasu
          wrote on last edited by
          #4

          The Error is : Characters found after end of SQL statement. I want to the two tables separately in my dataset. How to do so?

          VanithaVasu

          S N N 3 Replies Last reply
          0
          • V VanithaVasu

            The Error is : Characters found after end of SQL statement. I want to the two tables separately in my dataset. How to do so?

            VanithaVasu

            S Offline
            S Offline
            sidbaruah
            wrote on last edited by
            #5

            What is it that you are after? If you want more than two select statements in the table use a join. If you want different select statements for different tables or adapters, use different querystrings... I think for ur case u need : DataTable dt1=new DataTable(); DataTable dt2=new DataTable(); dt1="first sql select query result"; dt2="second sql select query result"; dataset ds=new dataset(); ds.Tables.Add(dt1); ds.Tables.Add(dt2); Hope that helps!!!

            I was born dumb!! :laugh:Programming made me laugh:laugh:!!! --sid--

            1 Reply Last reply
            0
            • V VanithaVasu

              The Error is : Characters found after end of SQL statement. I want to the two tables separately in my dataset. How to do so?

              VanithaVasu

              N Offline
              N Offline
              N a r e s h P a t e l
              wrote on last edited by
              #6

              Insetd of trying this: DataAdapter=new OleDbDataAdapter("select * from Table1;select * from Table2",connection); Try this: SqlDataAdapter adpt1 = new SqlDataAdapter("Select * From Table1", con); DataSet ds = new DataSet(); adpt1.Fill(ds); SqlDataAdapter adpt2 = new SqlDataAdapter("Select * From Table2", con); adpt2.Fill(ds); return ds;

              Naresh Patel

              1 Reply Last reply
              0
              • V VanithaVasu

                The Error is : Characters found after end of SQL statement. I want to the two tables separately in my dataset. How to do so?

                VanithaVasu

                N Offline
                N Offline
                N a v a n e e t h
                wrote on last edited by
                #7

                VanithaVasu wrote:

                I want to the two tables separately in my dataset. How to do so?

                As I told before, stored procedure's would be better approach for your problem. Write a stored procedure like

                CREATE PROCEDURE [dbo].[MultipleSelect]

                AS

                SELECT * FROM FisrtTable
                SELECT * FROM SecondTable

                GO

                Now Set command type to stored procedures for your OleDbCommand. Pass this stored procedures and fill dataset. This will give you two tables in dataset. Returning multiple recordset is a recommended practice by MSDN, which boosts performance.


                My Website | Ask smart questions

                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