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. Visual Basic
  4. Problem populating DataSet

Problem populating DataSet

Scheduled Pinned Locked Moved Visual Basic
helpdatabasesecuritytestingbeta-testing
11 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.
  • C Offline
    C Offline
    carrigart
    wrote on last edited by
    #1

    Hi, I am trying to use the Fill() method of dataAdapter class to fill a dataset but Im getting a SqlException error when I run my code. The error says Invalid object name 'Testing'. My database name is Runner.mdf and Testing is a table in my database. Heres my code. Hope someone can help. Thanks Dim ds As New DataSet Dim cn As New SqlConnection() Dim connString As String = "Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Documents\Runner.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True" cn.ConnectionString = connString cn.Open() Dim da As New SqlDataAdapter("SELECT * FROM Testing", cn) da.Fill(ds)

    N W T 3 Replies Last reply
    0
    • C carrigart

      Hi, I am trying to use the Fill() method of dataAdapter class to fill a dataset but Im getting a SqlException error when I run my code. The error says Invalid object name 'Testing'. My database name is Runner.mdf and Testing is a table in my database. Heres my code. Hope someone can help. Thanks Dim ds As New DataSet Dim cn As New SqlConnection() Dim connString As String = "Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Documents\Runner.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True" cn.ConnectionString = connString cn.Open() Dim da As New SqlDataAdapter("SELECT * FROM Testing", cn) da.Fill(ds)

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

      carrigart wrote:

      SELECT * FROM Testing

      Is this query executing successfully in query browser?

      Navaneeth How to use google | Ask smart questions

      C 3 Replies Last reply
      0
      • N N a v a n e e t h

        carrigart wrote:

        SELECT * FROM Testing

        Is this query executing successfully in query browser?

        Navaneeth How to use google | Ask smart questions

        C Offline
        C Offline
        carrigart
        wrote on last edited by
        #3

        How do you use the query browser. Is that the same as the object browser. I'm not familiar with both of them anyway

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

          carrigart wrote:

          SELECT * FROM Testing

          Is this query executing successfully in query browser?

          Navaneeth How to use google | Ask smart questions

          C Offline
          C Offline
          carrigart
          wrote on last edited by
          #4

          Yeah I figured out how to use the query browser and my query is working fine. It returns the contents of my database. Still getting the same error, so frustrating. :confused::confused::confused:

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

            carrigart wrote:

            SELECT * FROM Testing

            Is this query executing successfully in query browser?

            Navaneeth How to use google | Ask smart questions

            C Offline
            C Offline
            carrigart
            wrote on last edited by
            #5

            and one more thing, the code executes fine when I comment out the line da.Fill(ds), So is there something wrong with my dataset.

            1 Reply Last reply
            0
            • C carrigart

              Hi, I am trying to use the Fill() method of dataAdapter class to fill a dataset but Im getting a SqlException error when I run my code. The error says Invalid object name 'Testing'. My database name is Runner.mdf and Testing is a table in my database. Heres my code. Hope someone can help. Thanks Dim ds As New DataSet Dim cn As New SqlConnection() Dim connString As String = "Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Documents\Runner.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True" cn.ConnectionString = connString cn.Open() Dim da As New SqlDataAdapter("SELECT * FROM Testing", cn) da.Fill(ds)

              W Offline
              W Offline
              Wendelius
              wrote on last edited by
              #6

              Do you have the database (runner.mdf) included in your project? If you do, select it from the project explorer and from properties, check two things: - path to the file - is Copy to output directory true If copy to output directory is true, you should attach the database from the projects debug/bin folder, since each time you start the project the db is copied to that folder. Also note that in this case, all modifications done by program are not reflected to the original database, which is included to the project.

              The need to optimize rises from a bad design.My articles[^]

              C 1 Reply Last reply
              0
              • W Wendelius

                Do you have the database (runner.mdf) included in your project? If you do, select it from the project explorer and from properties, check two things: - path to the file - is Copy to output directory true If copy to output directory is true, you should attach the database from the projects debug/bin folder, since each time you start the project the db is copied to that folder. Also note that in this case, all modifications done by program are not reflected to the original database, which is included to the project.

                The need to optimize rises from a bad design.My articles[^]

                C Offline
                C Offline
                carrigart
                wrote on last edited by
                #7

                Yes the database is included in my project. I have checked the properties and the 'Copy to output directory' is set to 'Copy Always'. I'm not sure that I get you. Is it that the Path to the file should be the file in the debug/bin folder. So would I have to change and connection string and setup a new data source. Bit confused sorry

                W 1 Reply Last reply
                0
                • C carrigart

                  Yes the database is included in my project. I have checked the properties and the 'Copy to output directory' is set to 'Copy Always'. I'm not sure that I get you. Is it that the Path to the file should be the file in the debug/bin folder. So would I have to change and connection string and setup a new data source. Bit confused sorry

                  W Offline
                  W Offline
                  Wendelius
                  wrote on last edited by
                  #8

                  carrigart wrote:

                  would I have to change and connection string and setup a new data source

                  Yes, exactly, you should modify the connection string and attach the mdf from your projects debug/bin folder. You don't have to create a new datasource, just modify the connection string.

                  carrigart wrote:

                  Bit confused sorry

                  Nothing to be sorry about :)

                  The need to optimize rises from a bad design.My articles[^]

                  C 1 Reply Last reply
                  0
                  • W Wendelius

                    carrigart wrote:

                    would I have to change and connection string and setup a new data source

                    Yes, exactly, you should modify the connection string and attach the mdf from your projects debug/bin folder. You don't have to create a new datasource, just modify the connection string.

                    carrigart wrote:

                    Bit confused sorry

                    Nothing to be sorry about :)

                    The need to optimize rises from a bad design.My articles[^]

                    C Offline
                    C Offline
                    carrigart
                    wrote on last edited by
                    #9

                    Fixed it :-D . Only took me like a day :doh: . I changed the path off my connection string. Bit of a school boy error :doh: :doh: :doh:. Well its a lesson learnt anyway. Thanks for your help

                    W 1 Reply Last reply
                    0
                    • C carrigart

                      Fixed it :-D . Only took me like a day :doh: . I changed the path off my connection string. Bit of a school boy error :doh: :doh: :doh:. Well its a lesson learnt anyway. Thanks for your help

                      W Offline
                      W Offline
                      Wendelius
                      wrote on last edited by
                      #10

                      You're welcome :)

                      The need to optimize rises from a bad design.My articles[^]

                      1 Reply Last reply
                      0
                      • C carrigart

                        Hi, I am trying to use the Fill() method of dataAdapter class to fill a dataset but Im getting a SqlException error when I run my code. The error says Invalid object name 'Testing'. My database name is Runner.mdf and Testing is a table in my database. Heres my code. Hope someone can help. Thanks Dim ds As New DataSet Dim cn As New SqlConnection() Dim connString As String = "Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Documents\Runner.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True" cn.ConnectionString = connString cn.Open() Dim da As New SqlDataAdapter("SELECT * FROM Testing", cn) da.Fill(ds)

                        T Offline
                        T Offline
                        TheComputerMan
                        wrote on last edited by
                        #11

                        This may sound daft, but have you tried it by populating a command and then setting the dataadapter.selectcommand to the command?

                        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