I am having a problem with ExecuteNonQuery.
I have this code:
Try
strsql = "Insert into [Action] values (" &
EndItem.intItemIdentifier & ", " & intActionIdentifier
& ", '" & strOrg & "', '" & strStat & "', '" & strStatDate
& "', '" & strDesc & "', '" & strTake & "')"
Dim cmd As New OleDbCommand(strsql, conn)
cmd.ExecuteNonQuery()
Catch oledbExc As OleDbException
MessageBox.Show(oledbExc.ToString, _
"", MessageBoxButtons.OK, MessageBoxIcon.Error)
Catch ex As Exception
MessageBox.Show(ex.Message, "", _
MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
I get this error message:
ExecuteNonQuery requires an open and available
Connection. The connection's current state is closed.
Yet, I have the connection open at the top of the form and
have used it in other instances and it runs perfectly.
Public Class ActionEdit
'Inherits System.Windows.Forms.Form
Inherits System.Windows.Forms.Form
'Public Shared CriticalParts As Form
Public Shared conStr As String
= "Provider=Microsoft.JET.OLEDB.4.0;data
source=c:\\CPRdatabase.mdb"
' Create connection object
Public Shared conn As OleDbConnection = New
OleDbConnection(conStr)
I am not sure what I am missing that gives me an error
here and not anywhere else in my form.
Thanks in advance!
Elena