Private Sub cmdUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdUpdate.Click


        Dim conn As New OleDbConnection("<connection string>")
        Dim hasErrors As Boolean = False


        Try

            If txtUserName.Text <> "" Then



                Dim SQL As String = "UPDATE addresses SET PinCode= '" & txtPinCode.Text & "' , " & _
                "Occupation= '" & txtOccupation.Text & "' , " & _
                "Balance='" & txtBalance.Text & "' , " & _
                "Age='" & txtAge.Text & "' , " & _
                "WHERE UserName=" & txtUserName.Text & "'"

                txtStatus.Text &= vbCrLf & "Sending query: " & SQL


                ' Dim hasErrors As Boolean = False

                conn.Open()

                Dim com As New OleDbCommand(SQL, conn)
            End If
            If com.ExecuteNonQuery = 0 Then

                hasErrors = True

            End If

            conn.Close()


            If Not hasErrors Then

                txtStatus.Text &= vbCrLf & "Query Successful" & vbCrLf

            Else

                txtStatus.Text &= vbCrLf & "You may only update an existing record. "

            End If



        Catch exception As System.Data.OleDb.OleDbException

            If conn.State = ConnectionState.Open Then

                conn.Close()

            End If

            Console.WriteLine(exception.StackTrace)

            txtStatus.Text &= exception.ToString

        End Try

End Sub


i have make above code to update.

If com.ExecuteNonQuery = 0 Then

at above com is not declare..
please help someone

Place below code after the com declaration

If com.ExecuteNonQuery = 0 Then                 hasErrors = True             End If             conn.Close()              If Not hasErrors Then                 txtStatus.Text &= vbCrLf & "Query Successful" & vbCrLf             Else                 txtStatus.Text &= vbCrLf & "You may only update an existing record. "             End If
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.