【发布时间】:2016-12-04 22:19:17
【问题描述】:
大家好,我的数据库项目的 CRUD 项目几乎完成了。我只是想完成并完成删除功能。
query = string.Format("DELETE FROM customers WHERE `cid`= {0};", mDeleteTextBox);
我的变量 mDeleteTextBox 填充了我想要的值。 我的查询有什么问题?
错误信息
An unhandled exception of type 'MySql.Data.MySqlClient.MySqlException' occurred in MySql.Data.dll
Additional information: 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 '.TextBox, Text: 6' at line 1
【问题讨论】:
-
另外,您的
{0}需要有引号,或者更好的是,使用参数化查询:stackoverflow.com/questions/652978/… -
另外,检查 mDeleteTextBox 中的类型是否为字符串。也许你想写 mDeleteTextBox.Text?
-
Nigrimmist 你说的很对,谢谢!
标签: c# mysql winforms desktop-application