日期:2014-05-18  浏览次数:20763 次

恳求高手帮忙看看这段代码错在哪?
private string SetInsertSql(string sTableName,string scpCode,string sNum,string sPrice)
{
string sSql = "INSERT INTO " + sTableName  
+ " ( htlb,htbh,ckbh,ckmc,rq,khbh,dwmc,bmbh,jbr,bz,rq1,cpbh,cpmc,gg,txm,jldw,sl0,dj0,"
+ "cb,sl1,je1,dj,zsl,zje,zcb,je2,zje0,qxbz,sm,sm2,sm3,sm4 "
+ ") VALUES ( "
+"'" + "2" + "',"
+"'" + "CY00000111" + "',"
+"'" + "01" + "',"
+"'" + "配送中心" + "',"
+"#" + DateTime.Now.Date.ToString("MM/dd/yy") + "#,"
+"'" + "" + "',"
+"'" + "" + "',"
+"'" + " " + "',"
+"'" + "" + "',"
+"'" + " " + "',"
+"#" + DateTime.Now.Date.AddYears(1).ToString("MM/dd/yy") + "#,"
+"'" + " " + "',"
+"'" + " " + "',"
+"'" + " " + "',"
+"'" + " " + "',"
+ sNum + "," 
+ sPrice + ","
+ "1" + ","
+ "2" + ","
+ "3" + ","
+ sPrice + ","
+ "0" + ","
+ "0" + ","
+ "0" + ","
+ "0" + ","
+ "0" + ","
+ "'" + "',"
+ "'" + "',"
+ "'" + "',"
+ "'" + "',"
+ "'" + "'"
+ ")"; 
return sSql;
}
编译测试的时候老是提示“INSERT INTO语句错误”

------解决方案--------------------
这个太麻烦了

是inser语句出问题了

你调试到时候 看看sSql这个语句到底生成什么了
在sql里面执行一下会提示哪里出错了
------解决方案--------------------
不会吧,SQL拼得这么不清晰啊
------解决方案--------------------
我以前也遇到过,要么是你在考的时候出现了中英文的转换,要么是在写的时候

小写了一个'"或许是这些东东的问题,要仔细检查一下才好,因为太长,所以……

总之一定是语法错误,或是规则错误,是不是数字也加了""号了????
------解决方案--------------------
前后值 个数不一致
------解决方案--------------------
你在插入语句处设置个断点,调试将该SQL语句的值获取,然后在查询分析器中检测一下,不就可以发现错误了。
------解决方案--------------------
+"#" + DateTime.Now.Date.ToString("MM/dd/yy") + "#," 
这个什么意思?? #10/20/08#,这也能插入??除非'#10/20/08#'
------解决方案--------------------
把sql语句放到查询分析器运行,看看什么问题
如果没问题的话,在看程序
------解决方案--------------------
太长了吧
一步步调试
把SQL语句的内容放到查询分析器执行一下