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 = -; }
/// <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 == -)
{
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 == - && Value != null && Value.Length <= )
{
param.Size = ;
}
else
{
param.Size = Length;
}
param.DbType = IsAnsi ? (IsFixedLength ? DbType.AnsiStringFixedLength : DbType.AnsiString) : (IsFixedLength ? DbType.StringFixedLength : DbType.String);
command.Parameters.Add(param);
}
}

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

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

    之前一直在pom文件配置的数据库连接url,很多配置都写在pom文件中导致配置文件太长 新项目将配置写到不同的文件夹中得properties文件中了 db.url直接复制的pom文件中的 p.p1 { ...

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

    由于工作原因我们需要通过php访问我们以前的Sql Server 2005数据,所以就有了这篇文章的诞生.废话就少说了,做程序设计的最不喜欢兜圈子了.用简介步骤说明问题,往下看.系统:   Linux ...

  3. php连mssql中文乱码问题

    我在将一个aspx+mssql的系统做成php+mssql的系统时,感觉架构大不一样,aspx多是aspx页面+aspx.cs后台协同开发,多用可视化空间开发,而php我则选用了smarty模板,感觉 ...

  4. 写入mssql出现乱码

    1.出现乱码的场景如下: --------------------------------------------------------------------------------------- ...

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

    php5.3的情况下,用pdo的dblib驱动无法连接mssql的,根据官方的描述,5.2已经修改这个bug,5.3没有. 用php自带的mssql函数可以的.编译freetds,php_mssql, ...

  6. BeautifulSoup下Unicode乱码解决

    今天在用scrapy爬某个网站的数据,其中DOM解析我用的是BeautifulSoup,速度上没有XPath来得快,不过因为用了习惯了,所以一直用的bs,版本是bs4 不过在爬取过程中遇到了一些问题, ...

  7. mssql 中文乱码 字库集 问题解决方法

    The database could not be exclusively locked to perform the operation(SQL Server 5030错误解决办法)   SQL S ...

  8. java insert mysql 中文乱码

    jdbc:mysql://192.168.1.77:3306/db360?useUnicode=true&characterEncoding=UTF-8 drop database if ex ...

  9. python2 + Django 中文传到模板页面变Unicode乱码问题

    1.确保views页面首行设置了默认编码   # -*-coding:utf-8 -*- 2.确保html页面的编码为 utf-8 3.确保项目setting文件设置了 LANGUAGE_CODE = ...

随机推荐

  1. NOIp2018爆零记

    Day-2~Day0 考前抱佛脚,赶紧刷刷各种模板 Day 1 在开考之前打好了拍子模板,然后试题密码就发下来了(这是我前面的神仙打了\(100\)多行\(emacs\)的配置\(QAQ\)). 先按 ...

  2. Dos 批处理 Shutdown

    第一步: win + R,打开"运行" 第二步: 输入cmd 第三步: 输入color a或color b改成自己喜欢的颜色 第四步: 在shutdown后面输入不同的命令达到不同 ...

  3. BZOJ 1996: [Hnoi2010]chorus 合唱队(区间dp)

    题目: https://www.lydsy.com/JudgeOnline/problem.php?id=1996 题解: 这题刚拿到手的时候一脸懵逼qwq,经过思考与分析(看题解),发现是一道区间d ...

  4. JAVA中循环删除list中元素

    文章来源: https://www.cnblogs.com/pcheng/p/5336903.html JAVA中循环遍历list有三种方式for循环.增强for循环(也就是常说的foreach循环) ...

  5. MVC aspx

    客户端服务器---Model(模型)---View(视图)---Control(控制器) 1.ASP.NET  MVC 2.新建项目引擎选aspx.在Controllers创建控制器,默认启动Home ...

  6. Eclipse 在线安装properties编辑插件

    在eclipse中,如果在properties文件中写中文,会被自动保存成unicode编码,如lab.submitbutton=\u63d0\u4ea4.     这在查看properties文件时 ...

  7. 斯坦福大学公开课机器学习: advice for applying machine learning | deciding what to try next(revisited)(针对高偏差、高方差问题的解决方法以及隐藏层数的选择)

    针对高偏差.高方差问题的解决方法: 1.解决高方差问题的方案:增大训练样本量.缩小特征量.增大lambda值 2.解决高偏差问题的方案:增大特征量.增加多项式特征(比如x1*x2,x1的平方等等).减 ...

  8. 关于ComponentName组件名称的使用

    ComponentName,顾名思义,就是组件名称,通过调用Intent中的setComponent方法,我们可以打开另外一个应用中的Activity或者服务. 实例化一个ComponentName需 ...

  9. 根据指定的key,将二维数组的value转换为string,适用于mysql的in查询

    function array_unique_join($arr,$param){ $utm_source_arr = array_unique(array_column($arr,$param)); ...

  10. python学习笔记--文件重命名,删除及文件夹

    文件重命名 import os os.rename('123.txt','456.txt') 删除文件 >>> import os >>> os.remove('4 ...