Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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

Posted

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

Posted

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.

Posted

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?

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...