具有78个单选按钮的调查表的c#mysql insert或upadte命令语法

hkmswyz6  于 2021-06-21  发布在  Mysql
关注(0)|答案(1)|浏览(389)

我有一个c#win表单,其中包含一个弹出面板,其中包含78个单选按钮。调查有一个提交按钮,它将数据插入mysql表。click事件背后的代码应该允许更新和插入(因为人们可能会分几个阶段填写调查)。我遇到的问题是mysql insert命令似乎有语法问题,因为单击submit时会引发以下异常。。。
第1行的“1”附近的sql语法错误
我的insert语句当前

MySqlCommand cmd = new MySqlCommand("INSERT INTO central_db.azt_image VALUES ('" + SerialCombo.Text + "', '" + Global.cust_dfe + "', '" + EngImgcomboBx.Text + "', '" + SerialCombo.Text + "', '" + AssetLocTxtBx.Text + "', '" + AssetNameTxtBx.Text + "', '" + (ImgL1Pend.Checked ? "1" : "0") + "', '" + (ImgL2Pend.Checked ? "1" : "0") + "', '" + (ImgL3Pend.Checked ? "1" : "0") + "', '" + (ImgL4Pend.Checked ? "1" : "0") + "', '" + (ImgL5Pend.Checked ? "1" : "0") + "', '" + (ImgL6Pend.Checked ? "1" : "0") + "', '" + (ImgL7Pend.Checked ? "1" : "0") + "', '" + (ImgL8Pend.Checked ? "1" : "0") + "', '" + (ImgL9Pend.Checked ? "1" : "0") + "', '" + (ImgL10Pend.Checked ? "1" : "0") + "', '" + (ImgL11Pend.Checked ? "1" : "0") + "', '" + (ImgL12Pend.Checked ? "1" : "0") + "', '" + (ImgL13Pend.Checked ? "1" : "0") + "', '" + (ImgL14Pend.Checked ? "1" : "0") + "', '" + (ImgL15Pend.Checked ? "1" : "0") + "', '" + (ImgL16Pend.Checked ? "1" : "0") + "', '" + (ImgL17Pend.Checked ? "1" : "0") + "', '" + (ImgL18Pend.Checked ? "1" : "0") + "', '" + (ImgL19Pend.Checked ? "1" : "0") + "', '" + (ImgL20Pend.Checked ? "1" : "0") + "', '" + (ImgL21Pend.Checked ? "1" : "0") + "', '" + (ImgL22Pend.Checked ? "1" : "0") + "', '" + (ImgL23Pend.Checked ? "1" : "0") + "', '" + (ImgL24Pend.Checked ? "1" : "0") + "', '" + (ImgL25Pend.Checked ? "1" : "0") + "', '" + (ImgL26Pend.Checked ? "1" : "0") + "', '" + (ImgL1NA.Checked ? "1" : "0") + "', '" + (ImgL2NA.Checked ? "1" : "0") + "', '" + (ImgL3NA.Checked ? "1" : "0") + "', '" + (ImgL4NA.Checked ? "1" : "0") + "', '" + (ImgL5NA.Checked ? "1" : "0") + "', '" + (ImgL6NA.Checked ? "1" : "0") + "', '" + (ImgL7NA.Checked ? "1" : "0") + "', '" + (ImgL8NA.Checked ? "1" : "0") + "', '" + (ImgL9NA.Checked ? "1" : "0") + "', '" + (ImgL10NA.Checked ? "1" : "0") + "', '" + (ImgL11NA.Checked ? "1" : "0") + "', '" + (ImgL12NA.Checked ? "1" : "0") + "', '" + (ImgL13NA.Checked ? "1" : "0") + "', '" + (ImgL14NA.Checked ? "1" : "0") + "', '" + (ImgL15NA.Checked ? "1" : "0") + "', '" + (ImgL16NA.Checked ? "1" : "0") + "', '" + (ImgL17NA.Checked ? "1" : "0") + "', '" + (ImgL18NA.Checked ? "1" : "0") + "', '" + (ImgL19NA.Checked ? "1" : "0") + "', '" + (ImgL20NA.Checked ? "1" : "0") + "', '" + (ImgL21NA.Checked ? "1" : "0") + "', '" + (ImgL22NA.Checked ? "1" : "0") + "', '" + (ImgL23NA.Checked ? "1" : "0") + "', '" + (ImgL24NA.Checked ? "1" : "0") + "', '" + (ImgL25NA.Checked ? "1" : "0") + "', '" + (ImgL26NA.Checked ? "1" : "0") + "', '" + (ImgL1Comp.Checked ? "1" : "0") + "', '" + (ImgL2Comp.Checked ? "1" : "0") + "', '" + (ImgL3Comp.Checked ? "1" : "0") + "', '" + (ImgL4Comp.Checked ? "1" : "0") + "', '" + (ImgL5Comp.Checked ? "1" : "0") + "', '" + (ImgL6Comp.Checked ? "1" : "0") + "', '" + (ImgL7Comp.Checked ? "1" : "0") + "', '" + (ImgL8Comp.Checked ? "1" : "0") + "', '" + (ImgL9Comp.Checked ? "1" : "0") + "', '" + (ImgL10Comp.Checked ? "1" : "0") + "', '" + (ImgL11Comp.Checked ? "1" : "0") + "', '" + (ImgL12Comp.Checked ? "1" : "0") + "', '" + (ImgL13Comp.Checked ? "1" : "0") + "', '" + (ImgL14Comp.Checked ? "1" : "0") + "', '" + (ImgL15Comp.Checked ? "1" : "0") + "', '" + (ImgL16Comp.Checked ? "1" : "0") + "', '" + (ImgL17Comp.Checked ? "1" : "0") + "', '" + (ImgL18Comp.Checked ? "1" : "0") + "', '" + (ImgL19Comp.Checked ? "1" : "0") + "', '" + (ImgL20Comp.Checked ? "1" : "0") + "', '" + (ImgL21Comp.Checked ? "1" : "0") + "', '" + (ImgL22Comp.Checked ? "1" : "0") + "', '" + (ImgL23Comp.Checked ? "1" : "0") + "', '" + (ImgL24Comp.Checked ? "1" : "0") + "', '" + (ImgL25Comp.Checked ? "1" : "0") + "', '" + (ImgL26Comp.Checked ? "1" : "0") + "', '" + ImgNoteTxt.Text + "') ON DUPLICATE KEY UPDATE;", conn);

因为每次插入或更新都会为每一列指定一个值,所以我没有声明列标题。我不是mysqlMaven(远非如此),我不确定问题是命令的结构还是语法。。。任何帮助都会得到很大的帮助,因为我已经为此奋斗了几天。

ftf50wuq

ftf50wuq1#

好吧,我发现我的insert语句有问题。。。在insert语句之后使用on duplicate key update选项时,必须显式设置要更新的值,即。

INSERT INTO some_database.some_table ( key, first_name, last_name, current_score) VALUES ("123", "John", "Doe", 69) ON DUPLICATE KEY UPDATE current_score=69;

一旦我明确列出了我想要在发现重复键时更新的列,insert语句就会正常工作。。。
谢谢你的评论,stackoverflow社区太棒了。。。

相关问题