Database problem, need urgent help

nock8

Member
Joined
May 9, 2009
Messages
5
Programming Experience
Beginner
hi. I am working on a computing school project and have encountered the following problem when i was trying to link to a access 2007 database:

"ExecuteNonQuery: Connection property has not been initialized."

this is the code:


Dim connect_string As String = _
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\................"

Dim conn_db_extras_test2003 As New OleDb.OleDbConnection(connect_string)
conn_db_extras_test2003.Open()

Dim cmd As New OleDbCommand( _
"INSERT INTO cmm21.mdb (Team1, Team2, Map1, Map2, Map3, Score1, Score2, Score3, League, Size, Date) " & _
"VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)")

cmd.Parameters.Add(New OleDbParameter("Team1", Form2.yourteam_textbox.Text))
cmd.Parameters.Add(New OleDbParameter("Team2", Form2.opponentteam_textbox.Text))
cmd.Parameters.Add(New OleDbParameter("Map1", map1_combobox.Text))
cmd.Parameters.Add(New OleDbParameter("Map2", map2_combobox.Text))
cmd.Parameters.Add(New OleDbParameter("Map3", map3_combobox.Text))
cmd.Parameters.Add(New OleDbParameter("Score1", score1_listbox.Text))
cmd.Parameters.Add(New OleDbParameter("Score2", score2_listbox.Text))
cmd.Parameters.Add(New OleDbParameter("Score3", score3_listbox.Text))
cmd.Parameters.Add(New OleDbParameter("League", league_combobox.Text))
cmd.Parameters.Add(New OleDbParameter("Size", size_combobox.Text))
cmd.Parameters.Add(New OleDbParameter("Date", date_label.Text))

cmd.ExecuteNonQuery()

conn_db_extras_test2003.Close()
conn_db_extras_test2003.Dispose()





I don't understand why this error keeps coming up and the project's deadline is close... :(, i really need some urgent help...
 
First up, please post in the most appropriate forum for the topic. We have a big section dedicated to data access and another forum dedicated to WinForms data access so any question on databases obvioulsy doesn't belong in the VB.NET General forum. Thread moved.

As for the question, you've created an OleDbConnection object but you haven't told the OleDbCommand to execute over that connection. As the error message says, you haven't initialised the Connection property of the command. Check out the MSDN documentation for the OleDbCommand class and you'll see that there's several ways to tell the command which connection to use.
 
I'd also check your table name - is it really called "cmm21.mdb" ?
 
Back
Top