我的代码现在是这样的,因为我忘记在更新表后添加连接到我的数据库,但仍然无法正常工作
Private Sub cmdRegistar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdRegistar.Click
myConnToAccess = New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0; Data Source = 'D:\PAP\LoginForm\LoginForm\bin\debug\login.mdb'")
myConnToAccess.Open()
Try
Dim x As String
Dim str As String
x = ComboBox1.Text
str = "UPDATE UserTable set Password = '" & txtPass.Text & "' where Username = '" & x & "'"
Dim cmd As OleDbCommand = New OleDbCommand(str, myConnToAccess)
myConnToAccess.Close()
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
因为您可以看到代码没有任何错误,它编译并运行得很好,它只是不起作用,组合框值来自我正在尝试使用命令更新的相同数据库。我的所有其他连接都很好用,我的添加,搜索。
答案 0 :(得分:0)
您何时实际将str
传递到数据库?你不应该有str.Execute
之类的内容吗?除此之外,你还有一句错误:
str = "UPDATE UserTable set Password" & txtPass.text & "where Username= '" & x & "'"
应该是:
str = "UPDATE UserTable set Password = '" & txtPass.text & "' where Username = '" & x & "'"
答案 1 :(得分:0)
密码是一个保留字,请试试这个:
str = "UPDATE UserTable set [Password] = '" & txtPass.Text & "' where Username = '" & x & "'"