problems connecting to database

pettachi

Member
Joined
Oct 24, 2005
Messages
5
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
 
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 dont know how to create a connection, look up OleDbConnection in msdn
 
Ok thx, im gone check the msdn library. Is there mentionned how to make a connection?

Its the first time i work with a database connection, im still at school, and we havent seen it yet.
 
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?
 
Back
Top