0

I cant figure out whats wrong with this,when i update a record from my list view a pop up appears saying no value given for one or more required parameters.

heres my code:

 Private Sub BtnUpdate_Click(sender As Object, e As EventArgs) Handles BtnUpdate.Click
    Try
        Dim SqlQuery As String = "UPDATE UsersTable Set AccountType = '" & CmbAccountType.Text & "' , Username = '" & TxtUsername.Text & "' , UserPassword = '" & TxtPassword.Text & "' , Firstname = '" & TxtFirstname.Text & "' , Lastname = '" & TxtLastname.Text & "' , Sex = '" & CmbSex.Text & "',Birthdate = '" & DateTimePickerBirthdate.Text & "' , ContactNumber = '" & TxtContact.Text & "' , Address = '" & TxtAddress.Text & "' WHERE UserID = " & id & ";"
        Dim SqlCommand As New OleDbCommand
        With SqlCommand
            .CommandText = SqlQuery
            .Connection = Conn
            .ExecuteNonQuery()
        End With
        MsgBox("Account successfully updated!")
        loadlistview()
    Catch ex As Exception
        MsgBox(ex.Message)
    End Try
End Sub

Private Sub BtnDelete_Click(sender As Object, e As EventArgs) Handles BtnDelete.Click
    Try
        Dim SqlQuery As String = "DELETE FROM ProductTable WHERE UserID = " & id & ";"
        Dim SqlCommand As New OleDbCommand
        With SqlCommand
            .CommandText = SqlQuery
            .Connection = Conn
            .ExecuteNonQuery()
        End With
        MsgBox("Account deleted.")
        loadlistview()
    Catch ex As Exception
        MsgBox(ex.Message)
    End Try
End Sub
jeromeee
  • 11
  • 5

1 Answers1

0

The problem is in the WHERE condition which you used in your query. so you can correct it by using the following query

In update query :

 Dim SqlQuery As String = "UPDATE UsersTable Set AccountType = '" & CmbAccountType.Text & "'....................." & _
 "WHERE UserID = '" & id & "';" '<----- you miss a single quote in where clause.

In Delete query :

Dim SqlQuery As String = "DELETE FROM ProductTable WHERE UserID = '" & id & "';"