Dapper.net Insert mssql unicode 乱码问题

1、效果:

2、处理方法:

 /// <summary>
        /// insert single sql
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="sql"></param>
        /// <param name="param"></param>
        /// <param name="connectionString"></param>
        /// <returns></returns>
        public static int Insert<T>(string sql, dynamic param = null, string connectionString = null) where T : class, new()
        {
            using (IDbConnection conn = OpenConnection(connectionString))
            {
                return conn.Execute(sql, (object)param,null,null,null);
            }
        }
  public static readonly string InsertSql = @"Insert into SpreadApiErrorMsgs(Id,ControllerName,ActionName,Message,SoluWay,CreateDate)
                                                    values(@Id,@ControllerName,@ActionName,@Message,@SoluWay,@CreateDate)";
        /// <summary>
        /// insert single sql
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="sql"></param>
        /// <param name="param"></param>
        /// <param name="connectionString"></param>
        /// <returns></returns>
        public static int Insert<T>(string sql, dynamic param = null, string connectionString = null) where T : class, new()
        {
            using (IDbConnection conn = OpenConnection(connectionString))
            {
                return conn.Execute(sql, (object)param,null,null,null);
            }
        }

PS:Dapper源码:

 /// <summary>
    /// This class represents a SQL string, it can be used if you need to denote your parameter is a Char vs VarChar vs nVarChar vs nChar
    /// </summary>
    sealed partial class DbString : Reasonable.Spread.Dapper.SqlMapper.ICustomQueryParameter
    {
        /// <summary>
        /// Create a new DbString
        /// </summary>
        public DbString() { Length = -1; }
        /// <summary>
        /// Ansi vs Unicode
        /// </summary>
        public bool IsAnsi { get; set; }
        /// <summary>
        /// Fixed length
        /// </summary>
        public bool IsFixedLength { get; set; }
        /// <summary>
        /// Length of the string -1 for max
        /// </summary>
        public int Length { get; set; }
        /// <summary>
        /// The value of the string
        /// </summary>
        public string Value { get; set; }
        /// <summary>
        /// Add the parameter to the command... internal use only
        /// </summary>
        /// <param name="command"></param>
        /// <param name="name"></param>
        public void AddParameter(IDbCommand command, string name)
        {
            if (IsFixedLength && Length == -1)
            {
                throw new InvalidOperationException("If specifying IsFixedLength,  a Length must also be specified");
            }
            var param = command.CreateParameter();
            param.ParameterName = name;
            param.Value = (object)Value ?? DBNull.Value;
            if (Length == -1 && Value != null && Value.Length <= 4000)
            {
                param.Size = 4000;
            }
            else
            {
                param.Size = Length;
            }
            param.DbType = IsAnsi ? (IsFixedLength ? DbType.AnsiStringFixedLength : DbType.AnsiString) : (IsFixedLength ? DbType.StringFixedLength : DbType.String);
            command.Parameters.Add(param);
        }
    }
时间: 2024-08-06 09:54:25

Dapper.net Insert mssql unicode 乱码问题的相关文章

BeautifulSoup下Unicode乱码解决

今天在用scrapy爬某个网站的数据,其中DOM解析我用的是BeautifulSoup,速度上没有XPath来得快,不过因为用了习惯了,所以一直用的bs,版本是bs4 不过在爬取过程中遇到了一些问题,其中一个是Unicode转码问题,这也算是python中一个著名问题了. 我遇到的算是BeautifulSoup中的一个奇葩bug吧,在网页中经常会有 &nbsp 这种标记,称为 non-breaking space character, 本来这个应该是忽略的,但在bs中会把这个符号 转义成为一个u

SpringMVC + mybatis + Druid insert 数据库中文乱码,查询无乱码

之前一直在pom文件配置的数据库连接url,很多配置都写在pom文件中导致配置文件太长 新项目将配置写到不同的文件夹中得properties文件中了 db.url直接复制的pom文件中的 p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Monaco } span.s1 { color: #3933ff } jdbc:mysql://127.0.0.1:3306/portal?useUnicode=true&characterEncodin

php连mssql中文乱码问题

我在将一个aspx+mssql的系统做成php+mssql的系统时,感觉架构大不一样,aspx多是aspx页面+aspx.cs后台协同开发,多用可视化空间开发,而php我则选用了smarty模板,感觉很好用,一切都在自己掌握之中,开源的就是好.但是在期间使用mssql extention的时候遇到了中文乱码问题: mssql默认使用GB2312编码,而php使用UTF-8,能Google到的解决方案很少,但是却很简单: 简单的说就是使用iconv函数就ok了: 1.执行sql语句前,使用$sql

Linux下用freetds连接mssql中文乱码的问题【参考1】

由于工作原因我们需要通过php访问我们以前的Sql Server 2005数据,所以就有了这篇文章的诞生.废话就少说了,做程序设计的最不喜欢兜圈子了.用简介步骤说明问题,往下看.系统:   Linux数据库: Sql Server 2005 1.下载FreeTDS  官方网站:http://www.freetds.org  2.安装FreeTDS# tar zxvf freetds-current.tgz(解压)# ./configure --prefix=/usr/local/freetds

写入mssql数据乱码

1.出现乱码的场景如下: ------------------------------------------------------------------------------------------------------------------------------------------------------------------ 1)c#代码如下: private int InsertBaseReport(int year, long mainId, Guid? orgId,

Linux下用freetds连接mssql中文乱码的问题【参考2】

php5.3的情况下,用pdo的dblib驱动无法连接mssql的,根据官方的描述,5.2已经修改这个bug,5.3没有. 用php自带的mssql函数可以的.编译freetds,php_mssql,pdo_dblib参数如下: ./configure --prefix=/usr/local/freetds --with-tdsver=8.0 --enable-msdblib./configure --with-php-config=/usr/local/php/bin/php-config -

php mssql 中文各种乱码

1 查询输出时乱码  (SELECT ) 因为MSSQL 数据库一般都是 GBK 编码,所以在php页面中加入 header('Content-Type:text/html; charset=GBK'); 也可以使用 以下语句查看: 然后按对应表设置字符集. SELECT COLLATIONPROPERTY('Chinese_PRC_90_CI_AI', 'CodePage') 返回值对应表: 936 简体中文GBK 950 繁体中文BIG5 437 美国/加拿大英语 932 日文 949 韩文

php连接微软MSSQL(sql server)完全攻略

http://www.jb51.net/article/98364.htm php连接微软MSSQL(sql server)完全攻略 作者:吵吵 字体:[增加 减小] 类型:转载 时间:2016-11-27我要评论 在研究ezSQL的时候就看到了mssql_connect()等一些php提供的连接MSSQL的函数,本以为php这个开源的风靡世界的编程语言对连接微软的数据应该是不在话下的,但是到真正执行的时候,才发现困难多多 在研究ezSQL的时候就看到了mssql_connect()等一些php

CentOS6.6 x64+Nginx1.3.8/Apache-httpd 2.4.3+PHP5.4.8(php-fpm)+MySQL5.5.28+CoreSeek4.1源码编译安装

系统为CentOS6.6 x64服务器版精简安装. 准备工作 部署安装目录 /usr/local/* /var/lib/* /var/lib64/* 下载源文件 #cd /usr/local/src wget http://cdn.mysql.com/Downloads/MySQL-5.5/mysql-5.5.28.tar.gz wget http://cdn.mysql.com/Downloads/MySQL-5.6/mysql-5.6.10.tar.gz wget http://www.ng