zoukankan      html  css  js  c++  java
  • MySql 参数赋值bug (MySql.Data, Version=6.9.6.0 沙雕玩意)

    直接将参数赋值为常量0则参数值为null,出现异常:MySql.Data.MySqlClient.MySqlException (0x80004005): Column 'PayType' cannot be null

    public static long CreateIntegralPay(long memId, decimal payAmount, decimal buyIntegral)
    {
        var id = BitConverter.ToInt64(Guid.NewGuid().ToByteArray(), 0);
        var sqlBuffer = new StringBuilder();
        sqlBuffer.AppendLine("insert into `memberintegralrecordpay` (`Id`,`MemberId`,`PayType`,`PayAmount`,`BuyIntegral`,`PayStatus`,`RecordTime`,`Remark`)");
        sqlBuffer.AppendLine("values(@Id, @MemberId, @PayType, @PayAmount, @BuyIntegral, @PayStatus, @RecordTime, @Remark);");
        //sqlBuffer.AppendLine("select @@identity; ");
        const int val= 0;
        var sqlParameters = new MySql.Data.MySqlClient.MySqlParameter[]
        {
                new MySql.Data.MySqlClient.MySqlParameter("@Id",id),
                new MySql.Data.MySqlClient.MySqlParameter("@MemberId",memId),
                new MySql.Data.MySqlClient.MySqlParameter("@PayType", 0),
                new MySql.Data.MySqlClient.MySqlParameter("@PayAmount", payAmount),
                new MySql.Data.MySqlClient.MySqlParameter("@BuyIntegral",buyIntegral),
                new MySql.Data.MySqlClient.MySqlParameter("@PayStatus",val),
                new MySql.Data.MySqlClient.MySqlParameter("@RecordTime",DateTime.Now),
                new MySql.Data.MySqlClient.MySqlParameter("@Remark",string.Empty)
        };
        if (DbHelper.ExecuteSql(sqlBuffer.ToString(), sqlParameters) > 0)
        {
            return id;
        }
        return 0;
    }
    

      

    将0用变量代替后没有问题

    public static long CreateIntegralPay(long memId, decimal payAmount, decimal buyIntegral)
    {
        var id = BitConverter.ToInt64(Guid.NewGuid().ToByteArray(), 0);
        var sqlBuffer = new StringBuilder();
        sqlBuffer.AppendLine("insert into `memberintegralrecordpay` (`Id`,`MemberId`,`PayType`,`PayAmount`,`BuyIntegral`,`PayStatus`,`RecordTime`,`Remark`)");
        sqlBuffer.AppendLine("values(@Id, @MemberId, @PayType, @PayAmount, @BuyIntegral, @PayStatus, @RecordTime, @Remark);");
        //sqlBuffer.AppendLine("select @@identity; ");
        int val = 0;
        var sqlParameters = new MySql.Data.MySqlClient.MySqlParameter[]
        {
                new MySql.Data.MySqlClient.MySqlParameter("@Id",id),
                new MySql.Data.MySqlClient.MySqlParameter("@MemberId",memId),
                new MySql.Data.MySqlClient.MySqlParameter("@PayType", val),
                new MySql.Data.MySqlClient.MySqlParameter("@PayAmount", payAmount),
                new MySql.Data.MySqlClient.MySqlParameter("@BuyIntegral",buyIntegral),
                new MySql.Data.MySqlClient.MySqlParameter("@PayStatus",val),
                new MySql.Data.MySqlClient.MySqlParameter("@RecordTime",DateTime.Now),
                new MySql.Data.MySqlClient.MySqlParameter("@Remark",string.Empty)
        };
        if (DbHelper.ExecuteSql(sqlBuffer.ToString(), sqlParameters) > 0)
        {
            return id;
        }
        return 0;
    }
    

      

  • 相关阅读:
    Windows光标形状
    函数对象(仿函数 functor)
    构造函数的初始化列表抛出异常
    <<Windows via C/C++>>学习笔记 —— 线程优先级【转】
    单例模式
    c++中的重载(Overload)、覆盖(重写,Override) 、隐藏与访问权限控制及using声明
    RTTI: dynamic_cast typeid
    抽象类 虚函数 声明与实现
    typedef 函数指针 数组 std::function
    Client Window坐标 RECT相关函数
  • 原文地址:https://www.cnblogs.com/dreamman/p/11367970.html
Copyright © 2011-2022 走看看