ExecuteNonQuery: Connection property has not been initialized.

What is wrong with my command to get ExecuteNonQuery: Connection property has not been initialized.

  Shared Function editpost(ByVal id As Integer, ByVal title As string, ByVal post As String, ByVal important As String, ByVal forumlock As String) As String

        Using con As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Documents and Settings\perkinj\My Documents\Visual Studio 2010\WebSites\runningprofiles\forums\forum.mdb")
            Dim cmd As New OleDbCommand
            con.Open()

            cmd.CommandText = "UPDATE forum (Title,Post,forumlock,important) VALUES ('" & title & "','', '" & post & "','" & important & "','" & forumlock & "') where ID = '" & id & "'"

            cmd.ExecuteNonQuery()
            con.Close()
        End Using

    End Function

Open in new window

runnerjp2005Asked:
Who is Participating?
 
DhaestCommented:
You need to add a reference between your command-object and your connection-object

Try this:

Using con As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Documents and Settings\perkinj\My Documents\Visual Studio 2010\WebSites\runningprofiles\forums\forum.mdb")
            Dim cmd As New OleDbCommand
            cmd.Connection = con
       
            cmd.CommandText = "UPDATE forum (Title,Post,forumlock,important) VALUES ('" & title & "','', '" & post & "','" & important & "','" & forumlock & "') where ID = '" & id & "'"

            con.Open()
            cmd.ExecuteNonQuery()
            con.Close()
        End Using

0
 
runnerjp2005Author Commented:
Syntax error in UPDATE statement.

 cmd.CommandText = "UPDATE forum (Title,Post,forumlock,important) VALUES ('" & title & "','" & post & "','" & important & "','" & forumlock & "') where ID = '" & id & "'"

Open in new window


0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.