岳不涛 2016-04-22 03:41
浏览 1544

SQL server 数据库@@Error变量值如何返回

其cmd的sql语句为:
private const string SQL_INSERT_ORDER = "Declare @ID int; Declare @ERR int;
INSERT INTO Orders VALUES(
@BillAddress1, @BillAddress2, @BillCity, @BillState, @BillZip, @BillCountry,(。。省略若干值。。) 'U');
SELECT @ID=@@IDENTITY; INSERT INTO OrderStatus VALUES(@ID, @ID, GetDate(), 'P'); SELECT @ERR=@@ERROR;";
INSERT INTO LineItem VALUES( "@ID, @LineNumber0,@ItemId0, @Quantity0,@Price0); SELECT @ERR=@ERR+@@ERROR;
我目前需要读出@ERR自定义变量的值,网上提供的c# 代码如下:
var cmd = new sqlcommand(..);
cmd.executenonquery();--先执行sql语句。
using (SqlDataReader rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection))
{
//Read the returned @ERR
rdr.Read();
// If the error count is not zero throw an exception
if (rdr.GetInt32(1) != 0)
throw new ApplicationException("DATA INTEGRITY ERROR ON ORDER INSERT - ROLLBACK ISSUED");
}--读取@err值
问题来了: 程序说没有有效的数据读入,应该怎么改?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 c程序不知道为什么得不到结果
    • ¥40 复杂的限制性的商函数处理
    • ¥15 程序不包含适用于入口点的静态Main方法
    • ¥15 素材场景中光线烘焙后灯光失效
    • ¥15 请教一下各位,为什么我这个没有实现模拟点击
    • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
    • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
    • ¥20 有关区间dp的问题求解
    • ¥15 多电路系统共用电源的串扰问题
    • ¥15 slam rangenet++配置