vb.net中的mysql语法错误 [英] error in mysql syntax in vb.net

查看:143
本文介绍了vb.net中的mysql语法错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我得到这个错误,而我测试下面的代码:

 您的SQL语法有一个错误;请检查与您的MySQL服务器版本对应的手册,以获取在'[student](ID,LASTNAME,FIRSTNAME,SCHOOL)VALUES('333','aaa','aaa','aaa') line 1 

我只是回收了我在处理ms sql数据库时使用的代码。所以语法必须是错误的。什么可能是正确的语法添加记录到mysql数据库?
这是我当前的代码:

  idnum = TextBox1.Text 
lname = TextBox2.Text
fname = TextBox3.Text
skul = TextBox4.Text


使用sqlcon作为新的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()

结束使用

请帮助,谢谢

解决方案

尝试删除 student 表名,并在表名和列列表之间添加一个空格: [student](ID,... / p>

没有表模式定义我不能100%确定,但ParameterID看起来是一个int,但你是作为字符串传递值被包装在单引号中)。尝试首先将 TextBox1.Text 转换为 int (使用 Try.Parse


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. So the syntax must be wrong. What might be the correct syntax for adding records into mysql database? 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, ...

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 (i.e. value is wrapped in single quotes). Try converting TextBox1.Text to an int first (using Try.Parse)

这篇关于vb.net中的mysql语法错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆