如何使用VB.NET中的文本框更新数据库的多个表列值?

时间:2016-11-09 15:11:49

标签: vb.net

这是我的代码。但它不会对表值的多次更新起作用,它只在我更新单个值时才起作用。请帮助我,我是新手:(

  Private Sub SaveChanges_Click(sender As System.Object, e As     System.EventArgs) Handles SaveChanges.Click

    Dim con As New MySqlConnection("host = localhost; username = root; password = 1234; database = logindb")
    Dim cmd As New MySqlCommand

    con.Open()
    cmd.Connection = con
    cmd.CommandText = "UPDATE login SET username = '" & ChangeUsername.Text & "' and password = '" & ChangePassword.Text & "' and Security_Question1 ='" & ChangeSecQue1.Text & "' and Security_Question2 = '" & ChangeSecQue2.Text & "' and Security_Answer1 = '" & ChangeSecAns1.Text & "' and Security_Answer2 = '" & ChangeSecAns2.Text & "' "
    cmd.ExecuteNonQuery()
    MsgBox("Saved Changes!")
    con.Close()

End Sub

1 个答案:

答案 0 :(得分:0)

更改您的更新声明:

cmd.CommandText = "UPDATE login SET username = '" & ChangeUsername.Text & "' ,password = '" & ChangePassword.Text & "' ,Security_Question1 ='" & ChangeSecQue1.Text & "' ,Security_Question2 = '" & ChangeSecQue2.Text & "' ,Security_Answer1 = '" & ChangeSecAns1.Text & "' ,Security_Answer2 = '" & ChangeSecAns2.Text & "' "