C# 字符串报错 常量中有换行符
代码如下,我写了个函数,传递一个h字符串变量。字符串sql中我加了h的变量在中间,也加了@,但是总报错。提示很多错误:包括:常量中有换行符、字符文本中的字符太多、空字符、...
代码如下,我写了个函数,传递一个h字符串变量。字符串sql中我加了h的变量在中间,也加了@,但是总报错。提示很多错误:包括:常量中有换行符、字符文本中的字符太多、空字符、应输入;、应输入]等很多错误,但是我本身sql语句应该是正确的啊。去掉了h的变量变成纯string 就好。
public void getData(string h)
{ int xuhao = int.Parse(data.getdata("select max(NO) from gk_生产消耗 where 生产主机='"+h+"'", connstr));
int gkxuhao = int.Parse(data.getdata("select max(xuhao) from ",gkconnstr));
//下面是报错的字符串
string sql=@"SELECT xuhao as NO, '"+h+"' AS 生产主机,datetime1 AS 生产时间,xufang AS 生产方量, 0 AS 当前盘次,
Peigl1 AS [1理论值], GL1 AS [1实际值], Peigl2 AS [2理论值], GL2 AS [2实际值],
PeiGL3 AS [3理论值], GL3 AS [3实际值],PeiGL4 AS [4理论值], GL4 AS [4实际值],
Peisn1 AS [5理论值], sn1 AS [5实际值],Peisn2 AS [6理论值], sn2 AS [6实际值],
Peisn3 AS [7理论值], sn3 AS [7实际值], Peishui AS [8理论值],shui AS [8实际值],
Peiye1 AS [9理论值], ye1 AS [9实际值],Peiye2 AS [10理论值],ye2 AS [10实际值],
Peidaye1 AS [11理论值], daye1 AS [11实际值],Peimei1 AS [12理论值], fmei1 AS [12实际值],
Peimei2 AS [13理论值], fmei2 AS [13实际值],Peimei3 AS [14理论值], fmei3 AS [14实际值],
Peifen1 AS [15理论值], fen1 AS [15实际值],Peifen2 AS [16理论值], fen2 AS [16实际值],
peibi AS 任务单号, peibi AS 配比单号, sgdw AS 单位名称, gcmc AS 工程名称, Address AS 工程地址, buwei AS 施工部位, '' AS 浇注方式, '' AS 出单时间,shusongche AS 车辆编号, siji AS 司机, biaohao AS 产品标号, caozuoyuan AS 生产人员,'' AS 运输单号, '' AS 生产线,0 as 本车方量,case when (zhonglei='砂浆') then 1 else 0 end as 是否砂浆 from [GK_海诺工控1耗料]
where xuhao >"+xuhao+" and host="+h+"";
..........
} 展开
public void getData(string h)
{ int xuhao = int.Parse(data.getdata("select max(NO) from gk_生产消耗 where 生产主机='"+h+"'", connstr));
int gkxuhao = int.Parse(data.getdata("select max(xuhao) from ",gkconnstr));
//下面是报错的字符串
string sql=@"SELECT xuhao as NO, '"+h+"' AS 生产主机,datetime1 AS 生产时间,xufang AS 生产方量, 0 AS 当前盘次,
Peigl1 AS [1理论值], GL1 AS [1实际值], Peigl2 AS [2理论值], GL2 AS [2实际值],
PeiGL3 AS [3理论值], GL3 AS [3实际值],PeiGL4 AS [4理论值], GL4 AS [4实际值],
Peisn1 AS [5理论值], sn1 AS [5实际值],Peisn2 AS [6理论值], sn2 AS [6实际值],
Peisn3 AS [7理论值], sn3 AS [7实际值], Peishui AS [8理论值],shui AS [8实际值],
Peiye1 AS [9理论值], ye1 AS [9实际值],Peiye2 AS [10理论值],ye2 AS [10实际值],
Peidaye1 AS [11理论值], daye1 AS [11实际值],Peimei1 AS [12理论值], fmei1 AS [12实际值],
Peimei2 AS [13理论值], fmei2 AS [13实际值],Peimei3 AS [14理论值], fmei3 AS [14实际值],
Peifen1 AS [15理论值], fen1 AS [15实际值],Peifen2 AS [16理论值], fen2 AS [16实际值],
peibi AS 任务单号, peibi AS 配比单号, sgdw AS 单位名称, gcmc AS 工程名称, Address AS 工程地址, buwei AS 施工部位, '' AS 浇注方式, '' AS 出单时间,shusongche AS 车辆编号, siji AS 司机, biaohao AS 产品标号, caozuoyuan AS 生产人员,'' AS 运输单号, '' AS 生产线,0 as 本车方量,case when (zhonglei='砂浆') then 1 else 0 end as 是否砂浆 from [GK_海诺工控1耗料]
where xuhao >"+xuhao+" and host="+h+"";
..........
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询