SQL Update命令不更新数据库

时间:2019-06-15 16:42:30

标签: sql vb.net

我正在尝试在用户完成游戏后更新其高分。此代码运行后,数据库中的高分不会更新。

Dim con2 As New OleDbConnection
con2.ConnectionString = "Provider=microsoft.jet.oledb.4.0;Data Source=C:\Users\User1\Desktop\Project_Game\accounts1.mdb"
con2.Open()

Dim dc As OleDbCommand
dc = New OleDbCommand("UPDATE Users SET Highscore=@score WHERE Username=@currentUser", con2)
dc.Parameters.AddWithValue("@currentUser", loggedUsername)
dc.Parameters.AddWithValue("@score", score)
dc.ExecuteNonQuery()
con2.Close()

score变量包含玩家得分的整数值,loggedUsername变量包含字符串形式的已登录用户的用户名。

2 个答案:

答案 0 :(得分:0)

参数必须相反。

答案 1 :(得分:0)

Dim con2 As New OleDbConnection
con2.ConnectionString = "Provider=microsoft.jet.oledb.4.0;Data Source=C:\Users\User1\Desktop\Project_Game\accounts1.mdb"
con2.Open()

Dim dc As OleDbCommand
dc = New OleDbCommand("UPDATE Users SET Highscore=@score WHERE Username=@currentUser", con2)
dc.Parameters.AddWithValue("@score", score)
dc.Parameters.AddWithValue("@currentUser", loggedUsername)
dc.ExecuteNonQuery()
con2.Close()