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 = ...
随机推荐
- Anaconda For Linux (附C#交互式编程的引入)
汇总系列:https://www.cnblogs.com/dunitian/p/4822808.html#ai Jupyter美化: https://www.cnblogs.com/dotnetcra ...
- Ubuntu 18.04 安装微信(Linux通用)
Linux相关的知识:https://www.cnblogs.com/dunitian/p/4822808.html#linux 新增谷歌浏览器添加到桌面的彻底删除:https://www.cnblo ...
- web字体的设置
@font-face { font-family: 'OpenSans'; src: url("../fonts/open-sans-v15-latin-regular.woff2" ...
- LOJ#2353 货币兑换
CDQ分治优化斜率优化DP. 有个结论就是每天买完卖完....知道这个之后考虑今天卖的是哪天买的就能写出n²DP了. 发现形式是fi = max(aibj + cidj)的形式.我们可以把ci除出来, ...
- 【洛谷 P2430 严酷的训练】
题目背景 Lj的朋友WKY是一名神奇的少年,在同龄人之中有着极高的地位... 题目描述 他的老师老王对他的程序水平赞叹不已,于是下决心培养这名小子. 老王的训练方式很奇怪,他会一口气让WKY做很多道题 ...
- 一文看懂npm、yarn、pnpm之间的区别
文作者对比了当前主流的包管理工具npm.yarn.pnpm之间的区别,并提出了合适的使用建议,以下为译文: NPM npm是Node.js能够如此成功的主要原因之一.npm团队做了很多的工作,以确保n ...
- 认识Jmeter工具
1.Apache jmeter 是一个100%的纯java桌面应用,是Apache组织开发的基于java的压力测试工具.它最初被设计用于Web应用测试但后来扩展到其他测试领域,可以用于对静态的和动态的 ...
- 在html页面通过js实现复制粘贴功能
前言:要实现这个功能,常用的方式大概分为两类,第一种就是上插件,这个网上有大把,第二种就是直接用几行JS来实现. 这次说第二种实现方式,这方式有很大的局限性,只能用表单元素,并且不能设置disable ...
- TestNg 3.忽略测试
有些测试本身不想执行,但是删掉显得不合理,需要忽略这个测试用例 package com.course.testng; import org.testng.annotations.Test; publi ...
- postgresql安装概览
先从官网下载解压包:https://www.enterprisedb.com/download-postgresql-binaries 这种是解压后,进行配置就可以使用. 另外一种是要用./confi ...