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 = -; }
/// <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 乱码问题的更多相关文章
- SpringMVC + mybatis + Druid insert 数据库中文乱码,查询无乱码
之前一直在pom文件配置的数据库连接url,很多配置都写在pom文件中导致配置文件太长 新项目将配置写到不同的文件夹中得properties文件中了 db.url直接复制的pom文件中的 p.p1 { ...
- Linux下用freetds连接mssql中文乱码的问题【参考1】
由于工作原因我们需要通过php访问我们以前的Sql Server 2005数据,所以就有了这篇文章的诞生.废话就少说了,做程序设计的最不喜欢兜圈子了.用简介步骤说明问题,往下看.系统: Linux ...
- php连mssql中文乱码问题
我在将一个aspx+mssql的系统做成php+mssql的系统时,感觉架构大不一样,aspx多是aspx页面+aspx.cs后台协同开发,多用可视化空间开发,而php我则选用了smarty模板,感觉 ...
- 写入mssql出现乱码
1.出现乱码的场景如下: --------------------------------------------------------------------------------------- ...
- Linux下用freetds连接mssql中文乱码的问题【参考2】
php5.3的情况下,用pdo的dblib驱动无法连接mssql的,根据官方的描述,5.2已经修改这个bug,5.3没有. 用php自带的mssql函数可以的.编译freetds,php_mssql, ...
- BeautifulSoup下Unicode乱码解决
今天在用scrapy爬某个网站的数据,其中DOM解析我用的是BeautifulSoup,速度上没有XPath来得快,不过因为用了习惯了,所以一直用的bs,版本是bs4 不过在爬取过程中遇到了一些问题, ...
- mssql 中文乱码 字库集 问题解决方法
The database could not be exclusively locked to perform the operation(SQL Server 5030错误解决办法) SQL S ...
- java insert mysql 中文乱码
jdbc:mysql://192.168.1.77:3306/db360?useUnicode=true&characterEncoding=UTF-8 drop database if ex ...
- python2 + Django 中文传到模板页面变Unicode乱码问题
1.确保views页面首行设置了默认编码 # -*-coding:utf-8 -*- 2.确保html页面的编码为 utf-8 3.确保项目setting文件设置了 LANGUAGE_CODE = ...
随机推荐
- codeforces #530 D(Sum in the tree) (树上贪心)
Mitya has a rooted tree with nn vertices indexed from 11 to nn, where the root has index 11. Each ve ...
- dbForge Studio for MySQL V8.0 Enterprise
上篇文章:JetBrains全家桶破解思路(最新更新:2018-12-24) 最适合从SQLServer转向MySQL的人使用(用起来基本上差不多) 最适合Net开发人员的MySQL IDE (不装V ...
- Java 判断相等
1.基本数据类型用 == long a = (long) 1234567890; long b = (long) 1234567890; if (a == b) { System.out.printl ...
- COGS 2392 2393 2395 有标号的二分图计数
有黑白关系: 枚举左部点(黑色点),然后$2^{i*(n-i)}$处理方法同:COGS 2353 2355 2356 2358 有标号的DAG计数 无关系: 发现,假设$f(i)$是一个连通块,对于一 ...
- [luogu4626][一道水题2]
题目链接 思路 这个首先想到质因数分解.然后发现只要对于每个质数将ans乘以这个质数在从1到n中出现过的最高指数次就行了. 这个\(10^8\)令人发指.一直tle,最后发现吸口氧才能过.. 代码 # ...
- C sockets Errno
在Windows下进行网络编程,免不了出现各种错误.在Linux下可以使用errno查看错误,但是根据stackoverflow上说,windows下应该使用: FormatMessage() WSA ...
- 转:upload.parseRequest为空
上传是items一直是空list.导致原因是struts2把原始的原来S2为简化上传功能,把所有的enctype="multipart/form-data"表单做了wrapper最 ...
- HDU3974 Assign the task
Assign the task Time Limit: 15000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- Ubuntu下载报错“文件尺寸不符”
最近学习openfoam,安装双系统后,根据官网进行安装openfoam,在文件的下载中会出现: “文件尺寸不符” 这个错误是因为网络不好造成的,或是请求的网站无回应. 解决的办法手机打开4G,打开热 ...
- Java Web 开发必须掌握的三个技术:Token、Cookie、Session
在Web应用中,HTTP请求是无状态的.即:用户第一次发起请求,与服务器建立连接并登录成功后,为了避免每次打开一个页面都需要登录一下,就出现了cookie,Session. Cookie Cookie ...