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;
}

  

原文地址:https://www.cnblogs.com/dreamman/p/11367970.html

时间: 2024-08-29 12:49:46

MySql 参数赋值bug (MySql.Data, Version=6.9.6.0 沙雕玩意)的相关文章

MySQL参数文件及参数修改方法

MySQL参数文件: MySQL数据库初始化参数由参数文件来设置,如果没有设置参数文件,mysql就按照系统中参数的默认值来启动. 在windows和linux上,参数文件可以被放在多个位置,数据库启动时按照不同的顺序来搜索,如果多个位置都有参数文件,则搜索顺序靠后的参数文件中的参数将覆盖前的参数. Windows上参数文件读取顺序 Linux上参数文件读取顺序 修改mysql参数的方法:

mysql参数优化辅助工具之mysqltuner

Mysqltuner.sql 的使用和安装. Mysqltuner 是一个mysql参数优化辅助工具,它可以对mysql进行全面的体检,然后给出针对性的体检报告 1.mysqltuner 下载 mysqltuner 官网:http://mysqltuner.com/ 可以下载最新版本的. 2.mysqltuner 的安装和使用. Mysqltuner  就是一套perl脚本,不需要任何的安装,将下载下来的tar安装包解压下就行了. [[email protected] software]# ta

关于参数net_buffer_length How MySQL Uses Memory

http://dev.mysql.com/doc/refman/5.6/en/memory-use.html The following list indicates some of the ways that the mysqld server uses memory. Where applicable, the name of the system variable relevant to the memory use is given: All threads share the MyIS

MySQL参数调优最佳实践

前言很多时候,RDS用户经常会问如何调优RDS MySQL的参数,为了回答这个问题,写一篇blog来进行解释: 哪一些参数不能修改,那一些参数可以修改:这些提供修改的参数是不是已经是最佳设置,如何才能利用好这些参数:哪些参数可以改细心的用户在购买RDS的时候都会看到,不同规格能够提供的最大连接数以及内存是不同的,所以这一些产品规格的限制参数:连接数.内存用户是不能够修改的,如果内存或者连接数出现了瓶颈: 内存瓶颈:实例会出现OOM,然后导致主备发生切换连接数瓶颈:应用不能新建立连接到数据库则需要

【改变mysql 日志位置Bug】Could not use mysql.log for logging (error 13)

今天手贱,看到mysql 的日志在/var/log/mysql下面.总是觉得别扭,于是就想改变日志的位置, 本人开发环境 vagrant  + ubuntu12.04 ,在/etc/mysql/mysql中修改了general_log的位置,放在/data/logs/mysql下面 然后重启服务,service mysql restart 查看错误日志发现说 /usr/sbin/mysqld: File '/data/logs/mysql/mysql.log' not found (Errcod

MySQL 参数文件及参数

MySQL的参数文件为----my.cnf 如何确定数据库读取的哪一个,命令给出了答案 [[email protected] home]# mysql --help |grep my.cnf                      order of preference, my.cnf, $MYSQL_TCP_PORT,/etc/my.cnf /etc/mysql/my.cnf /usr/local/mysql/etc/my.cnf ~/.my.cnf [[email protected] h

前段时间,接手一个项目使用的是原始的jdbc作为数据库的访问,发布到服务器上在运行了一段时间之后总是会出现无法访问的情况,登录到服务器,查看tomcat日志发现总是报如下的错误。    Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Data source rejected est

前段时间,接手一个项目使用的是原始的jdbc作为数据库的访问,发布到服务器上在运行了一段时间之后总是会出现无法访问的情况,登录到服务器,查看tomcat日志发现总是报如下的错误. Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Data source rejected establishment of connection, message from server: "Too man

Mysqldump参数大全 这 些参数 不同于 mysql 的那些参数(下边文章开头有链接) :2 种类型的参数含义是不一样的

Mysqldump参数大全  这 些参数 不同于 mysql 的那些参数  :2 种类型的参数含义是不一样的 Mysqldump参数大全(参数来源于mysql5.5.19源码) 参数 参数说明 --all-databases , -A 导出全部数据库. mysqldump -uroot -p --all-databases --all-tablespaces , -Y 导出全部表空间. mysqldump -uroot -p --all-databases --all-tablespaces -

mysql参数及解释

key_buffer_size: #*** MyISAM 特有的选项.即使你不使用 MyISAM 表,你仍应该将它设置为 8-64M,因为它也被用于内部的临时磁盘表.这个参数是用来设置索引块(index blocks)缓存的大小,它被所有线程共享,严格说是它决定了数据库索引处理的速度,尤其是索引读的速度.   max_allowed_packet: #**通用配置选项,能够处理的最大通信信息包大小,在客户端或者服务器端都可以设置.   table_open_cache #**通用配置选项,参数设