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

SQL 语句双引号怎么处理?搞了半天没弄懂这个
string sql =@"select P.FID as 商品编号,substring(P.FBarcode,1,12) AS 商品条码, substring(concat(trim(case when FUseSName = 1 then FSName else FSName1 end),trim(FSpec)),1,40) AS 商品名称,substring(trim(ifnull(ss.FValue,"")),1,2) as 商品单位,ifnull(P.FOutPrice,0) as 售价,ifnull(P.FInPrice,0) AS 进价,ifnull(P.FMemberPrice, 0) as 会员价,ifnull(S.FNum, 0) as 库存,ifnull(PS.FOperat,0) AS 状态 ,ifnull(P.FInfo,"") as 商品信息 from Product P Left Join systype ss on ss.FTypeName='ProdUnit' and ss.FItemID=p.FUnit Left Join Stock S on P.FID=S.FProdID and S.FStockID=2 Left Join ProdShop PS on PS.FProdID=P.FID and PS.FStockID=2 where P.FState<100 order by P.FBarcode";





SQL语句没有错,在MYSQL数据库中能正常执行

------解决方案--------------------
"" => """
------解决方案--------------------
'',双引号中套单引号
------解决方案--------------------
string sql =@"select P.FID as 商品编号,substring(P.FBarcode,1,12) AS 商品条码, substring(concat(trim(case when FUseSName = 1 then FSName else FSName1 end),trim(FSpec)),1,40) AS 商品名称,substring(trim(ifnull(ss.FValue,"""")),1,2) as 商品单位,ifnull(P.FOutPrice,0) as 售价,ifnull(P.FInPrice,0) AS 进价,ifnull(P.FMemberPrice, 0) as 会员价,ifnull(S.FNum, 0) as 库存,ifnull(PS.FOperat,0) AS 状态 ,ifnull(P.FInfo,"""") as 商品信息 from Product P Left Join systype ss on ss.FTypeName='ProdUnit' and ss.FItemID=p.FUnit Left Join Stock S on P.FID=S.FProdID and S.FStockID=2 Left Join ProdShop PS on PS.FProdID=P.FID and PS.FStockID=2 where P.FState<100 order by P.FBarcode";

因为你使用了 @
所以"" 表示一个"
------解决方案--------------------
string sql = string.Fomart("select P.FID as 商品编号……");
这么写试试
------解决方案--------------------
"" => """