Pregunta

Currently my program working fine for adding and update data , but when update the data it update all the data that from same StaffID.Even the Staff id adding new data and update the new data the old data from the same id will update all the old one. here is my code:

Using sqlConn2 As New MySqlConnection(strConnectionString)
            sqlConn2.Open()
            Using sqlComm2 As New MySqlCommand()

                sqlComm2.Connection = sqlConn2
                With sqlComm2


                    .CommandText = "update cr_record " & _
    "set cr_record.isu=@isu," & _
    "cr_record.Nama=@Nama," & _
    "cr_record.pnum=@pnum," & _
    "cr_record.date1=@date1," & _
    "cr_record.DeptDesc=@DeptDesc," & _
    "cr_record.email=@email," & _
    "cr_record.change1=@change1," & _
    "cr_record.reasonchange=@reasonchange," & _
    "cr_record.problem=@problem," & _
    "cr_record.priority=@priority," & _
    "cr_record.reasondescription=@reasondescription," & _
    "cr_record.systemrequest=@systemrequest " & _
    "where cr_record.Emplid=@Emplid and cr_number"
                    .CommandType = CommandType.Text
                    .Parameters.AddWithValue("@cr_id", cr_id)
                    .Parameters.AddWithValue("@Emplid", txt1.Text)
                    .Parameters.AddWithValue("@isu", ddl1.SelectedItem)
                    .Parameters.AddWithValue("@Nama", TextBox1.Text)
                    .Parameters.AddWithValue("@pnum", txt3.Text)
                    .Parameters.AddWithValue("@date1", txtDate.Text)
                    .Parameters.AddWithValue("@DeptDesc", txtdep.Text)
                    .Parameters.AddWithValue("@email", TextBox3.Text)
                    .Parameters.AddWithValue("@change1", ddl2.SelectedItem)
                    .Parameters.AddWithValue("@reasonchange", txt6.Text)
                    .Parameters.AddWithValue("@problem", ddl3.SelectedItem)
                    .Parameters.AddWithValue("@priority", rbl1.SelectedItem)
                    .Parameters.AddWithValue("@reasondescription", txt7.Text)
                    .Parameters.AddWithValue("@systemrequest", ddl4.SelectedItem)

                    '' .Parameters.AddWithValue("@attachment", FileUpload5)
                    ''  .Parameters.AddWithValue("@jobDesc", TextBox4.Text)
                    '' .Parameters.AddWithValue("@locDesc", TextBox5.Text)
                End With
                Try

                    sqlComm2.ExecuteNonQuery()
                    MsgBox("Data has been modified successfully!", MsgBoxStyle.Information, "Updated!")
                Catch ex As MySqlException
                    MsgBox(ex.Message.ToString())
                End Try
            End Using
        End Using
¿Fue útil?

Solución

Looks like you have not given value for the second attribute "cr_number" after "where" clause

.CommandText = "update cr_record " & _
"set cr_record.isu=@isu," & _
"cr_record.Nama=@Nama," & _
"cr_record.pnum=@pnum," & _
"cr_record.date1=@date1," & _
"cr_record.DeptDesc=@DeptDesc," & _
"cr_record.email=@email," & _
"cr_record.change1=@change1," & _
"cr_record.reasonchange=@reasonchange," & _
"cr_record.problem=@problem," & _
"cr_record.priority=@priority," & _
"cr_record.reasondescription=@reasondescription," & _
"cr_record.systemrequest=@systemrequest " & _
"where cr_record.Emplid=@Emplid and cr_number=@cr_number"
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top