从数据类型 varchar 转换为 numeric 时出错 怎么解决
cmd.CommandText = "insert into t_xsjjjcb(NB,Lou_NM,JCFS,JCJE,JCZPH,YHMC,JEFH,FPBH,czybm,fhczybm,zt,flag) values('" + textNM.Text + "','" + textLou_NM.Text + "','" + textJCFS.Text + "','" + textJCJE.Text + "','" + textJCZPH.Text + "','" + textYHMC.Text + "','" + textJEFH.Text + "','" + textFPBH.Text + "','" + textczybm.Text + "','" + textfhczybm.Text + "','" + ztDropDownList.Text + "','" + flagDropDownList.Text + "')";
这里JCJE 和JEFH是numeric类型的,现在的语句报错,从数据类型 varchar 转换为 numeric 时出错。但是如果去掉单引号,就报错说','附近有语法错误。怎么解决
------解决方案--------------------去掉两边的单引号
然后对JCJE, JEFH先进行整型转换在执行SQL语句
------解决方案--------------------单引号即可。http://bbs.csdn.net/topics/390026629
------解决方案--------------------
"insert into t_xsjjjcb(NB,Lou_NM,JCFS,JCJE,JCZPH,YHMC,JEFH,FPBH,czybm,fhczybm,zt,flag) values('" + textNM.Text + "','" + textLou_NM.Text + "','" + textJCFS.Text + "'," + Convert.ToDouble(textJCJE.Text) + ",'" + textJCZPH.Text + "','" + textYHMC.Text + "'," + Convert.ToDouble(textJEFH.Text) + ",'" + textFPBH.Text + "','" + textczybm.Text + "','" + textfhczybm.Text + "','" + ztDropDownList.Text + "','" + flagDropDownList.Text + "')";
------解决方案--------------------
把你的两个JCJE和JEFH的Text都转为int型变量,然后去掉单引号执行。