ODBC VB 抛出语法错误
我看不出我的 SQL 语句语法有什么问题,代码在这里:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Using Con1 As New Odbc.OdbcConnection("Driver={MySQL ODBC 5.1 Driver};Server=127.0.0.1;Database=MyGame;User=root; Password=MyPasswordWhichIWontTellYou;")
Dim mInsertSQL As String
mInsertSQL = "INSERT INTO Accounts (Username,Password,Str,Int,Agi,Money) VALUES ('" & txtUser.Text & "','" & txtPass.Text & "'," & Int(txtStr.Text) & "," & Int(txtInt.Text) & "," & Int(txtAgi.Text) & ",0);"
Dim Cmd1 As New Odbc.OdbcCommand(mInsertSQL, Con1)
Try
Con1.Open()
Cmd1.ExecuteNonQuery()
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Using
End Sub
为了清楚起见,实际的插入语句是带有一些数据的:
"INSERT INTO Accounts (Username,Password,Str,Int,Agi,Money) VALUES ('MyUsername','MyPassword',0,0,0,0)"
给出的错误是:
ERROR [42000] [MySQL][ODBC 5.1 Driver][mysqld-5.1.41]You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Int,Agi,Money) VALUES ('MyUsername','MyPassword',0,0,0,0)' at line 1
非常感谢。
I cant see what is wrong with my SQL statement syntax code is here:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Using Con1 As New Odbc.OdbcConnection("Driver={MySQL ODBC 5.1 Driver};Server=127.0.0.1;Database=MyGame;User=root; Password=MyPasswordWhichIWontTellYou;")
Dim mInsertSQL As String
mInsertSQL = "INSERT INTO Accounts (Username,Password,Str,Int,Agi,Money) VALUES ('" & txtUser.Text & "','" & txtPass.Text & "'," & Int(txtStr.Text) & "," & Int(txtInt.Text) & "," & Int(txtAgi.Text) & ",0);"
Dim Cmd1 As New Odbc.OdbcCommand(mInsertSQL, Con1)
Try
Con1.Open()
Cmd1.ExecuteNonQuery()
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Using
End Sub
Just for clarity the actual insert statement is this with some data:
"INSERT INTO Accounts (Username,Password,Str,Int,Agi,Money) VALUES ('MyUsername','MyPassword',0,0,0,0)"
The error given is:
ERROR [42000] [MySQL][ODBC 5.1 Driver][mysqld-5.1.41]You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Int,Agi,Money) VALUES ('MyUsername','MyPassword',0,0,0,0)' at line 1
Thanks alot.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
大胆猜测:“Int”作为字段名称可能会被保留,也许您可以尝试该字段的其他名称?
Wild Guess: 'Int' as a field name may be reserved, maybe you could try another name for the field?