我有一个包含三列的数据库表:User
,Pass
,Money
。我还有一个带有按钮的vb表单和一个名为TextBox
的{{1}}。用于更新数据库中Money
的查询代码是什么,因此它与表单中的Money
相同?
答案 0 :(得分:1)
答案 1 :(得分:1)
使用这段代码,您应该能够连接和更新Access数据库
Dim Connection As New OledbConnection("Provider=microsoft.Jet.oledb.4.0;DataSource=YourDatabase.mdb;")
Try
Connection.Open()
Dim Query = "UPDATE TableName SET Money = ? WHERE User = ?"
Dim command As New OleDbCommand
With command
.CommandText = Query
.Connection = Connection
.Parameters.AddWithValue("@p1", MoneyTextBox.Text)
.Parameters.AddWithValue("@p2", UserTextBox.Text)
End With
command.ExecuteNonQuery()
Catch exception As Exception
MessageBox.Show(exception.Message)
Finally
Connection.Close()
End Try
答案 2 :(得分:0)
使用更新查询
"update Databasename set Money='"& MoneyTextBox.Text &"' where user='" & UserTextBox.Text &"' and Pass='"PassTextBox.Text"' "