• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 470
  • Last Modified:

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

0
runnerjp2005
Asked:
runnerjp2005
1 Solution
 
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

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now