Problem with Data Connection

renata

Member
Joined
Aug 9, 2011
Messages
7
Programming Experience
Beginner
Hi there,
i'd like to pose a question. I am working on a project using visual studio 2010 and ms access 2010.
I have created a database with the desired tables. I connected my database to my application in order to show data from my database on my application and it worked.Along the way I had to create new tables to hold the information i wanted.So i created the desired tables and in order to "add" the newly created tables in my dataset I right-clicked my dataset,I chose Configure dataset with wizard and then ticked the newly created tables. I then drag-n-dropped them into the dataset.<br>At the point where i want to show any information regarding the two newly created tables i get an error saying:
(path_to_my_database.mdb) is not a valid path. Make sure that the path name is spelled correctly and that you are connected to the server on which the file resides.
When I tried creating a new project with the same database and the same code I get no such error.
Can someone help me figure out what's wrong??

Thanks in advance.
 
Hi jmcilhinney,my data connection string is: dbprovider = "PROVIDER=Microsoft.Jet.OLEDB.4.0;" dbsource = "Data Source = C:\Users\RnA\Documents\Visual Studio 2010\Projects\Educational Application\Educational Application\bin\Debug\edu_app.mdb" con.ConnectionString = dbprovider & dbsourceYes, the database path is correct. I use the above data connection string to pull other data from my database and it works fine. The problem arises when i want to pull data regarding my newly created tables.
 
Why are you building a connection string in code if you have a Data Source and typed DataSet? Can you show us the actual code you're using to connect to the database and retrieve and save data?
 
Shouldn't I build a connection String??
My code is:
Dim cb As New OleDb.OleDbCommandBuilder(da)
Dim dsNewStudentRow As DataRow

dsNewStudentRow = ds.Tables("edu_app").NewStudentRow()
dsNewStudentRow.Item("FirstName") = txtFirstName.Text
dsNewStudentRow.Item("Surname") = txtSurname.Text

ds.Tables("edu_app").Rows.Add(dsNewStudentRow)
da.Update(ds, "edu_app")
MsgBox("New Student has been added to the Database")

This is the code that I use to add a new student into my database.

Thanks for trying to help me.
 
If you used the Data Source wizard then you you have a typed DataSet with TableAdapters. That's the main point of the Data Source wizard. You're supposed to use that typed DataSet and its typed DataTables, etc, not create your own untyped DataSet and DataAdapetsr. Look in the Toolbox. That's where you'll find them. You can add them to your form like controls, or you can create them in code if you want. The connection is wrapped inside the TableAdapter, so it gets the connection string for itself from the the config file, where the Data Source wizard saved it.
 
Thanks for you help.

I've noticed the data adapters in the toolbox panel. I 'll give a try and post back here if i have any questions.


Again, thanks for your help.

Renata
 
Hi,
i tried using the typed datasets/adapters etc. provided as you suggest but I still get the same error. I added a new form to my existing project, I put a dataset,table adapters from the toolbox panel and then wrote this code for loading the first question with its answers.

Private Sub frmTest_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'TODO: This line of code loads data into the 'Edu_appDataSet.TestInfo' table. You can move, or remove it, as needed.
Me.TestInfoTableAdapter.Fill(Me.Edu_appDataSet.TestInfo)
'TODO: This line of code loads data into the 'Edu_appDataSet.Test' table. You can move, or remove it, as needed.
Me.TestTableAdapter.Fill(Me.Edu_appDataSet.Test)
inc = 0
Me.Label1.Text = Edu_appDataSet.Test(0).Question
Me.RadioButton1.Text = Edu_appDataSet.Test(inc).Answer1
Me.RadioButton2.Text = Edu_appDataSet.Test(inc).Answer2
Me.RadioButton3.Text = Edu_appDataSet.Test(inc).RightAnswer
End Sub
When I try running it it gives me the exact error as before (not providing a valid path to my database). What is it that I'm doing wrong?
I checked my application settings and saw that I have 2 connection strings!!
I then remembered that when I added a new data source connection it asked my that since my database is in a local folder if I wanted to be copied to the project folder and I chose yes.
Is this this causing the problem? Have into consideration that I'm not referring to the "wrong" connection string anywhere in my project.
Can someone please help me understand what's going on?

Thanks in advance.
 
Back
Top