[英]error in mysql syntax in vb.net
I get this error, while I'm testing the code below: 我在测试以下代码时收到此错误:
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 '[student](ID, LASTNAME, FIRSTNAME, SCHOOL) VALUES ('333', 'aaa', 'aaa', 'aaa')' at line 1
I just recycled the code that I used in manipulating ms sql database. 我只是回收了用于处理ms sql数据库的代码。 So the syntax must be wrong. 因此语法一定是错误的。 What might be the correct syntax for adding records into mysql database? 将记录添加到mysql数据库中的正确语法是什么? Here is my current code: 这是我当前的代码:
idnum = TextBox1.Text
lname = TextBox2.Text
fname = TextBox3.Text
skul = TextBox4.Text
Using sqlcon As New MySqlConnection("Server=localhost; Database=testing;Uid=root;Pwd=nitoryolai123$%^;")
sqlcon.Open()
Dim sqlcom As New MySqlCommand()
sqlcom.Connection = sqlcon
sqlcom.CommandText = "INSERT INTO [student](ID, LASTNAME, FIRSTNAME, SCHOOL) VALUES (@ParameterID, @ParameterLastName, @ParameterFirstName, @ParameterSchool)"
sqlcom.Parameters.AddWithValue("@ParameterID", TextBox1.Text)
sqlcom.Parameters.AddWithValue("@ParameterLastName", TextBox2.Text)
sqlcom.Parameters.AddWithValue("@ParameterFirstName", TextBox3.Text)
sqlcom.Parameters.AddWithValue("@ParameterSchool", TextBox4.Text)
sqlcom.ExecuteNonQuery()
End Using
Please help, thanks 请帮忙,谢谢
Try removing the square brackets from the student
table name, and adding a space between table name and column list: [student] (ID, ...
尝试从student
表名称中删除方括号,并在表名称和列列表之间添加一个空格: [student] (ID, ...
Without your table schema definition I can't be 100% sure, but ParameterID appears to be an int, but you are passing as a string (ie value is wrapped in single quotes). 没有表模式定义,我不能100%确定,但是ParameterID似乎是一个整数,但是您是以字符串形式传递的(即,值用单引号引起来)。 Try converting TextBox1.Text
to an int
first (using Try.Parse
) 首先尝试将TextBox1.Text
转换为int
(使用Try.Parse
)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.