C# ExecuteNonQuery() sql语法错误 20
SqlCommandcomm=newSqlCommand(strSQl1,THDataBase.Conn);returncomm.ExecuteNonQuery();变量...
SqlCommand comm = new SqlCommand(strSQl1, THDataBase.Conn);
return comm.ExecuteNonQuery();
变量comm没有问题. 主要是参数strSQl1.这个参数我是从txt文件中读出来的.是sql2000自动生成的.复制到查询分析器里也是没有问题的.但是ExecuteNonQuery();的时候就报错了看图!
sql语句也给上
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[NFH]') and OBJECTPROPERTY(id, N'IsView') = 1)
drop view [dbo].[NFH]
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE VIEW dbo.NFH
AS
SELECT TOP 100 PERCENT dbo.fac_stuff_sett.sett_code AS ID,
dbo.fac_stuff_purchase.pur_code AS 磅单号,
dbo.fac_stuff_purchase.farmer_name AS 农户名,
dbo.base_farmer.farmer_tele AS 联系方式,
dbo.fac_stuff_purchase.measure_unit AS 单位,
dbo.fac_stuff_purchase.GW AS 毛重, dbo.fac_stuff_purchase.tare AS 重1,
dbo.fac_stuff_purchase.tare_time AS 时间, NULL AS 运量,
dbo.fac_stuff_purchase.NW AS 重2,
dbo.fac_stuff_purchase.ConvertLintWeight AS 重3,
dbo.fac_stuff_purchase.ConvertCSWeight AS 重4,
dbo.fac_stuff_purchase.pur_sum AS 金,
dbo.fac_stuff_purchase.QT_No AS 单号,
dbo.fac_stuff_purchase.MKLZ AS 值,
dbo.fac_stuff_purchase.stuff_grade AS 级,
dbo.fac_stuff_purchase.impurity_PC AS 率,
dbo.fac_stuff_purchase.moisture_PC AS 2率,
dbo.fac_stuff_purchase.LPC_M AS 1分,
dbo.fac_stuff_purchase.LPC_GD AS 2衣分, NULL AS 水分, NULL ASa率,
dbo.fac_stuff_purchase.BJ_sum AS r价, dbo.fac_stuff_sett.sett_code AS d单号,
dbo.fac_invoice.invoice_No AS 发票号, dbo.fac_invoice.pur_sum AS 金额,
dbo.fac_invoice.invoice_date AS 结算时间,
dbo.base_farmer.farmer_IDC AS 证号
FROM dbo.fac_invoice INNER JOIN
dbo.fac_stuff_purchase ON
dbo.fac_invoice.pur_code = dbo.fac_stuff_purchase.pur_code INNER JOIN
dbo.base_farmer ON
dbo.fac_stuff_purchase.farmer_code = dbo.base_farmer.farmer_code INNER JOIN
dbo.fac_stuff_sett ON
dbo.fac_stuff_purchase.pur_code = dbo.fac_stuff_sett.pur_code
ORDER BY dbo.fac_stuff_sett.sett_code
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO 展开
return comm.ExecuteNonQuery();
变量comm没有问题. 主要是参数strSQl1.这个参数我是从txt文件中读出来的.是sql2000自动生成的.复制到查询分析器里也是没有问题的.但是ExecuteNonQuery();的时候就报错了看图!
sql语句也给上
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[NFH]') and OBJECTPROPERTY(id, N'IsView') = 1)
drop view [dbo].[NFH]
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE VIEW dbo.NFH
AS
SELECT TOP 100 PERCENT dbo.fac_stuff_sett.sett_code AS ID,
dbo.fac_stuff_purchase.pur_code AS 磅单号,
dbo.fac_stuff_purchase.farmer_name AS 农户名,
dbo.base_farmer.farmer_tele AS 联系方式,
dbo.fac_stuff_purchase.measure_unit AS 单位,
dbo.fac_stuff_purchase.GW AS 毛重, dbo.fac_stuff_purchase.tare AS 重1,
dbo.fac_stuff_purchase.tare_time AS 时间, NULL AS 运量,
dbo.fac_stuff_purchase.NW AS 重2,
dbo.fac_stuff_purchase.ConvertLintWeight AS 重3,
dbo.fac_stuff_purchase.ConvertCSWeight AS 重4,
dbo.fac_stuff_purchase.pur_sum AS 金,
dbo.fac_stuff_purchase.QT_No AS 单号,
dbo.fac_stuff_purchase.MKLZ AS 值,
dbo.fac_stuff_purchase.stuff_grade AS 级,
dbo.fac_stuff_purchase.impurity_PC AS 率,
dbo.fac_stuff_purchase.moisture_PC AS 2率,
dbo.fac_stuff_purchase.LPC_M AS 1分,
dbo.fac_stuff_purchase.LPC_GD AS 2衣分, NULL AS 水分, NULL ASa率,
dbo.fac_stuff_purchase.BJ_sum AS r价, dbo.fac_stuff_sett.sett_code AS d单号,
dbo.fac_invoice.invoice_No AS 发票号, dbo.fac_invoice.pur_sum AS 金额,
dbo.fac_invoice.invoice_date AS 结算时间,
dbo.base_farmer.farmer_IDC AS 证号
FROM dbo.fac_invoice INNER JOIN
dbo.fac_stuff_purchase ON
dbo.fac_invoice.pur_code = dbo.fac_stuff_purchase.pur_code INNER JOIN
dbo.base_farmer ON
dbo.fac_stuff_purchase.farmer_code = dbo.base_farmer.farmer_code INNER JOIN
dbo.fac_stuff_sett ON
dbo.fac_stuff_purchase.pur_code = dbo.fac_stuff_sett.pur_code
ORDER BY dbo.fac_stuff_sett.sett_code
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO 展开
2个回答
展开全部
//ExecuteNonQuery 为 Transaction 操作:
SqlTransaction tran = THDataBase.Conn.BeginTransaction();
SqlCommand comm = new SqlCommand(strSQl1, THDataBase.Conn, tran);
object result;
try
{
result = comm.ExecuteNonQuery();
}
catch{;;;} //自己catch
return result
// 你试试看
SqlTransaction tran = THDataBase.Conn.BeginTransaction();
SqlCommand comm = new SqlCommand(strSQl1, THDataBase.Conn, tran);
object result;
try
{
result = comm.ExecuteNonQuery();
}
catch{;;;} //自己catch
return result
// 你试试看
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询