hello guys

can u help me with code. Everytime i run the program and update the data in database. I got the error in this code

da.Update(ds, "reservationdata")
Dim dt As DataTable = ds.Tables("reservationdata")


        If resno.Text = "" Or custname.Text = "" Or custaddress.Text = "" Or TextBox1.Text = "" Or endTime.Text = "" Or amouttopaid.Text = "" Or InitialDeposite.Text = "" Or RemainingPayment.Text = "" Or DateTimePicker1.Text = "" Then
            MsgBox("Please fill the amount information for update", MsgBoxStyle.Exclamation, "UPDATE PAYMENT INFORMATION")
        Else
            Try
                With dt
                    .Rows(0)("resno") = resno.Text
                    .Rows(0)("custname") = custname.Text
                    .Rows(0)("custaddress") = custaddress.Text
                    .Rows(0)("facname") = facname.Text
                    .Rows(0)("amenityname") = amenityname.Text
                    .Rows(0)("startTime") = TextBox1.Text
                    .Rows(0)("endTime") = endTime.Text
                    .Rows(0)("amounttopaid") = amouttopaid.Text
                    .Rows(0)("InitialDeposite") = InitialDeposite.Text
                    .Rows(0)("RemainingPayment") = RemainingPayment.Text
                    .Rows(0)("datereservation") = DateTimePicker1.Text

                    MsgBox("Record successfully updated.", MsgBoxStyle.Information)

                    resno.Text = ""
                    custname.Text = ""
                    custaddress.Text = ""
                    facname.Text = "   Select Facility"
                    amenityname.Text = "   Select Amenity"
                    endTime.Text = ""
                    InitialDeposite.Text = ""
                    RemainingPayment.Text = "'"
                    amouttopaid.Text = "0"
                End With

            Catch ex As MySqlException
                MsgBox(ex.ToString)
            End Try

            da.Update(ds, "reservationdata")

        End If

ok tell me if what is the error of that because everytime I run the code after the msgbox("successfully....") and press ok button the error will appear in the da.Update(ds, "reservationdata") or anyone can fix my code please...:) wait the error is "Duplicate "2" to key 1 just like that. but when I change the value of resno there is no error but what I want is that to update only the data in "InitialDeposite.text").
I have only two data save in the table reservationdata and there is no duplicate data in resno which is the primary key.

Putting your da.Update(ds, "reservationdata") before the catch might give you more clues as to what your problem is.

it will work only for the data in the reservation no. 2 but when i try to do that the error is duplicate entry "3" for key 1

have you thought of issuing a dt.endedit just before your first msgbox.... and maybe issue your da.update just after that?

Edited 6 Years Ago by PerplexedB: n/a

what is the problem of my code...but in one of my form I use that code but updating data is working properly.

This question has already been answered. Start a new discussion instead.