Click here to Skip to main content
15,886,963 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I've been working with project using VB.NET and access as database. however when I have to update data stored I get the following error message: "No value given for one or more required parameters"

What I have tried:

 Private Sub Updatebtn_Click(sender As System.Object, e As System.EventArgs) Handles Updatebtn.Click
        If TextBox1.Text = "" Or TextBox2.Text = "" Or TextBox3.Text = "" Or TextBox4.Text = "" Or TextBox5.Text = "" Or ComboBox1.Text = "" Then
            MsgBox("Please Fill All Details")
            Exit Sub
        End If
        Try
            con.Close()
            con.Open()
            str = "UPDATE Customers set CustomerName=@name,Address=@Address,Phone=@Phone,EyePower=@EP,ConsutantDoctor=@CD where CustomerID=@CID"
            cmd = New OleDbCommand(str, con)
            cmd.Parameters.AddWithValue("@name", TextBox1.Text)
            cmd.Parameters.AddWithValue("@Address", TextBox2.Text)
            cmd.Parameters.AddWithValue("@Phone", TextBox3.Text)
            cmd.Parameters.AddWithValue("@EP", TextBox4.Text)
            cmd.Parameters.AddWithValue("@CD", TextBox5.Text)
            cmd.Parameters.AddWithValue("@CID", ComboBox1.Text)
            cmd.ExecuteNonQuery()

            MsgBox("Record Updated Successfully", MsgBoxStyle.Information, MsgBoxStyle.OkOnly)

        Catch ex As Exception
            MsgBox("Error", ex.Message)

        Finally
            con.Close()
        End Try
    End Sub
End Class
Posted
Updated 4-Aug-23 8:37am

1 solution

The code looks OK from here - but we have no access to your data, so we can't test it.

So it's going to be up to you to gather information.
Fortunately, you have a tool that will help you: the debugger.
Run your code in the debugger, and put a breakpoint on the first line in the method. When you hit the update button, execution will stop and hand control to you.
Single step through the method looking at the actual content of variables and watch what happens - it should be fairly obvious which row is causing the problem to occur when you try to commit the update.

Sorry, but we can't do any of that for you - time to learn a new and very useful skill: debugging!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900