Problem populating DataSet
-
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)
-
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)
carrigart wrote:
SELECT * FROM Testing
Is this query executing successfully in query browser?
Navaneeth How to use google | Ask smart questions
-
carrigart wrote:
SELECT * FROM Testing
Is this query executing successfully in query browser?
Navaneeth How to use google | Ask smart questions
-
carrigart wrote:
SELECT * FROM Testing
Is this query executing successfully in query browser?
Navaneeth How to use google | Ask smart questions
-
carrigart wrote:
SELECT * FROM Testing
Is this query executing successfully in query browser?
Navaneeth How to use google | Ask smart questions
-
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)
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[^]
-
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[^]
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
-
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
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[^]
-
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[^]
-
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
-
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)
This may sound daft, but have you tried it by populating a command and then setting the dataadapter.selectcommand to the command?