寻找薛定谔的猫

导航

 
sql += "'" + col.Table.Rows[tabParams.Rownum][col.Ordinal].ToString()+ "',";

使用for循环对SQL语句进行拼接的时候,循环到某个字段,不管怎么自加字符串的值都不变,得到的SQL语句是不完整的,如下

insert into jk_sample (FBMMC,FGZJH,FSBMC,FSBBH,FSBXH,x_Number,x_Name,x_Method,Weight,Moisture,SulfurArea,SulfurPeak,SulfurTime,Stad,Std,x_Date,x_Operator,Memo,initVolt,lparam,x,y) 

values('化学室','222','全自动测硫仪','03','5E-IRS3600','20200226045','A0588782','20191210','0.2968','0.68','3.32760320899911','0.105281323418624','154','2.47854333257062','2.47854333257062','2020/2/26 18:05:40','

后来查了一些网上的资料得知\0代表字符串的终止,而循环到的那个字段值就是\0。

C#对字符串自加,末尾出现\0,就会终止对此字符串的所有操作

因此需要将\0字符替换掉,就可以对字符串正常操作了

sql += "'" + col.Table.Rows[tabParams.Rownum][col.Ordinal].ToString().Replace("\0","") + "',";
insert into jk_sample (FBMMC,FGZJH,FSBMC,FSBBH,FSBXH,x_Number,x_Name,x_Method,Weight,Moisture,SulfurArea,SulfurPeak,SulfurTime,Stad,Std,x_Date,x_Operator,Memo,initVolt,lparam,x,y) 

values('化学室','222','全自动测硫仪','03','5E-IRS3600','20200226045','A0588782','20191210','0.2968','0.68','3.32760320899911','0.105281323418624','154','2.47854333257062','2.47854333257062','2020/2/26 18:05:40',' ','','8.563','217',:IMAGEDATA,:IMAGEDATA)

 

posted on 2020-04-02 16:26  teagueli  阅读(1950)  评论(1编辑  收藏  举报