这个查询不会执行一个简单的单行查询,我也没有看到任何错误,但仍然会出错。
INSERT IGNORE INTO Vendors ('Name','Address','Contact','Email','Fax')
VALUES('ehsan','tes# 235t','test','testmailcom','test');
错误:
Error Code: 1064
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
''Name','Address','Contact','Email','Fax') Values('ehsan','tes# 235t',
'test','tes' at line 1
这是实际代码:
cmd = new MySqlCommand("Insert IGNORE into Vendors('Name','Address','Contact','Email','Fax') Values(@name,@address,@contact,@email,@fax)", conn);
cmd.Parameters.AddWithValue("@name", name);
cmd.Parameters.AddWithValue("@address", address);
cmd.Parameters.AddWithValue("@contact", contact);
cmd.Parameters.AddWithValue("@email", email);
cmd.Parameters.AddWithValue("@fax", fax);
cmd.ExecuteNonQuery();
答案 0 :(得分:5)
在MySql中,您需要使用(`)
引用字段名称INSERT IGNORE INTO Vendors (`Name`,`Address`,`Contact`,`Email`,`Fax`)
VALUES('ehsan','tes# 235t','test','testmailcom','test');