MySQL insert into 语句中字符串报错
仅提供中文版本
在传入值时,在C#中代码直接传入string值,报错显示未找到符合列
1 | command += "INSERT INTO " + TableName + "(data_id,data_desc,data_price) VALUES(" + ids[i] + ", " + description[i] + "," + price[i] + ");"+"\r\n"; |
运行出错后发现是自己没有考虑到命令全部以字符串形式传入,此时description传入的字符串未带有双引号“ “,命令的字符串形式为:
1 | "insert into table (data_id,data_desc,data_price) |
可以看到description没有双引号所以命令出错,需要修改命令description加入单引号即可
1 | ", '" + description[i] + "' ," |
All articles on this blog are licensed under CC BY-NC-SA 4.0 unless otherwise stated.




