目前我的程序可以很好地添加和更新数据,但是当更新数据时,它会更新来自同一StaffID的所有数据。 这是我的代码:
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
看起来您还没有为"where"子句之后的第二个属性"cr_number"给出值
.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"