我在C#中为MySql数据库编写请求,并且需要在命令双引号的字符串中编写。就像是:
String command ="Insert into table (column) values ("" + textBox1.Text + "")";
但是我有C#的语法错误。当我尝试chenge时,
String command ="Insert into table (column) values ('" + textBox1.Text + "')";
我有Mysql(1054)的语法错误。行列的类型为varchar。如何在程序中正确编写此请求?
这是这样的:
string mystring = "We use \"a laser\"";
但!由于您尝试形成sql查询,因此您不应该自己这样做。您需要使用可保护您免受sql注入攻击的sql参数。
这是有关sql参数的简短课程:http : //www.csharp-station.com/Tutorial/AdoDotNet/lesson06
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句