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 = ...
随机推荐
- 逆元(inv)
当求解公式:(a/b)%m 时,因b可能会过大,会出现爆精度的情况,所以需变除法为乘法: 设c是b的逆元,则有b*c≡1(mod m): 则(a/b)%m = (a/b)*1%m = (a/b)*b* ...
- nodejs的某些api~(四)udp&dns
今天记udp/数据报套接字和dns. udp UDP/数据报套接字 => require('dgram');dgram.createServer([type],[cb]);type:可以是'ud ...
- 为什么分布式一定要有redis?
为什么分布式一定要有redis? 孤独烟 架构师小秘圈 昨天 作者:孤独烟 来自:http://rjzheng.cnblogs.com/ 1.为什么使用redis 分析:博主觉得在项目中使用red ...
- 商品详情页系统的Servlet3异步化实践
http://jinnianshilongnian.iteye.com/blog/2245925 博客分类: 架构 在京东工作的这一年多时间里,我在整个商品详情页系统(后端数据源)及商品详情页统一 ...
- Flask 自定义过滤器多个参数传入
非完整HTML文件: <div class="container" style="margin-top:50px;"> <div class= ...
- Java 读数据库字段时发现的一个现象
早上发现有一个网名叫“帅!是不需要理由”的一个人,在后台只能看到“帅!是不需要理”,“由”字就是不显示出来. 经过分析发现,在Access数据库中,name这个字段的长度是15,因为我知道Access ...
- C#面向对象中类的继承和扫描顺序和接口
1. 类的分类:普通基类.抽象基类(abstract class)1. 类的扫描顺序:a.先近后远 b.(向上扫描)以谁身份声明的变量就在谁身上开始扫描, 2. 扫描的特殊情况:普通基类 ...
- 【译】10. Java反射——数组
原文地址:http://tutorials.jenkov.com/java-reflection/arrays.html ======================================= ...
- (Prim算法)codeVs 1078 最小生成树
题目描述 Description 农民约翰被选为他们镇的镇长!他其中一个竞选承诺就是在镇上建立起互联网,并连接到所有的农场.当然,他需要你的帮助. 约翰已经给他的农场安排了一条高速的网络线路,他想把这 ...
- php php-fpm安装 nginx配置php
centos 6.2 linux下安装php5.6.6源码 PHP在 5.3.3 之后已经把php-fpm并入到php的核心代码中了. 所以php-fpm不需要单独的下载安装.要想php支持php-f ...