更新命令更新表中的所有数据

时间:2014-04-08 05:23:26

标签: mysql asp.net vb.net updates

目前我的程序正常工作,可以添加和更新数据,但是当更新数据时,它会更新来自同一StaffID的所有数据。即使员工ID添加新数据并更新新数据,来自同一ID的旧数据也会更新所有旧的。这是我的代码:

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

1 个答案:

答案 0 :(得分:1)

看起来你没有给第二个属性赋值#34; 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"