数据库记录未更新

时间:2017-05-22 07:44:42

标签: sql asp.net vb.net record

大家好我是新来的,我有问题在VB ASP.NET webform中更新我的数据库记录。我的代码将返回对话框,表示当cmd.ExecuteNonQuery()>成功更新记录时0,但数据库中的记录实际上没有更新。对不起,我的英语不好。请提前帮助谢谢。

Protected Sub btnUpdate_Click(sender As Object, e As EventArgs) Handles btnUpdate.Click
    Dim staffUsername As String = Session("StaffUsername").ToString()
    Dim staffFNm As String = txtStaffFNm.Text
    Dim staffLNm As String = txtStaffLNm.Text
    Dim staffEmail As String = txtStaffCpnyEmail1.Text + txtStaffCpnyEmail2.Text
    Dim staffBDay As String = txtBirthday.Text
    Dim staffPhone As String = txtPhoneNo.Text
    Using con As New SqlConnection(ConfigurationManager.ConnectionStrings("SupportSystemDB").ConnectionString)
        con.Open()

        Dim myCommand As New SqlCommand("UPDATE STAFF SET StaffFNm = @staffFNm, StaffLNm = @staffLNm, StaffEmail = @staffEmail, StaffBirthday = @staffBDay, StaffPhone = @staffPhone  WHERE StaffUsernm = @staffUsernm", con)
        myCommand.Parameters.AddWithValue("@staffFNm", staffFNm)
        myCommand.Parameters.AddWithValue("@staffLNm", staffLNm)
        myCommand.Parameters.AddWithValue("@staffEmail", staffEmail)
        myCommand.Parameters.AddWithValue("@staffBDay", staffBDay)
        myCommand.Parameters.AddWithValue("@staffPhone", staffPhone)
        myCommand.Parameters.AddWithValue("@staffUsernm", staffUsername)
        If myCommand.ExecuteNonQuery() > 0 Then
            Response.Write("<script>alert('Your Account Info Has Been Successfully Updated.');</script>")
            con.Close()
        Else
            Response.Write("<script>alert('Record Update Failed.');</script>")
        End If


    End Using
End Sub

0 个答案:

没有答案