pettachi Posted October 24, 2005 Posted October 24, 2005 Hello, When i try to connect to an access database , the program always struggles at this line, does someone know what it means? dataAdapter.InsertCommand.ExecuteNonQuery() This is the error i get An unhandled exception of type 'System.InvalidOperationException' occurred in system.data.dll Additional information: ExecuteNonQuery: Connection property has not been initialized. Greetz Quote
VagabondSW Posted October 24, 2005 Posted October 24, 2005 Did you first call the Open method of the connection object? Quote "Never ascribe to malice that which can adequately be explained by incompetence." -- Napolean Bonaparte
Diesel Posted October 25, 2005 Posted October 25, 2005 You have not specified the connection used for the command... Your constructor is most likely: Dim Dim command as new OleDbCommand(connectionString) Either use: Dim command as new OleDbCommand(connectionString, connection) or if a connection is not available at that point, set it later... command.Connection = connection If you don't know how to create a connection, look up OleDbConnection in msdn Quote
pettachi Posted October 25, 2005 Author Posted October 25, 2005 Ok thx, i'm gone check the msdn library. Is there mentionned how to make a connection? It's the first time i work with a database connection, i'm still at school, and we haven't seen it yet. Quote
pettachi Posted October 25, 2005 Author Posted October 25, 2005 this is my code Public Sub dataopslaan(ByVal inquery As String, ByVal dataAdapter As OleDb.OleDbDataAdapter, _ ByVal dataconnectie As OleDb.OleDbConnection) dataAdapter.InsertCommand.CommandText = inquery dataconnectie.Open() Try dataAdapter.InsertCommand.ExecuteNonQuery() Catch ex As OleDb.OleDbException MessageBox.Show(ex.Message, "Fout bij invoegen", MessageBoxButtons.OK, MessageBoxIcon.Error) End Try dataconnectie.Close(). End Sub I placed it in a module. I call dataopslaan like this : dataopslaan(query, Me.OleDbDataAdapter1, Me.OleDbConnection1) query = INSERT INTO ..... when i run the program he always gives my this error: An unhandled exception of type 'System.InvalidOperationException' occurred in system.data.dll Additional information: ExecuteNonQuery: Connection property has not been initialized. The program '[3608] connectietest.exe' has exited with code 0 (0x0). Does anybody know what i have to change? Quote
Administrators PlausiblyDamp Posted October 25, 2005 Administrators Posted October 25, 2005 You haven't told the command to use the connection, read the post from Diesel just above yours and try that. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.