MySQL 表与字段编码格式报错
MySQL 表与字段编码格式报错
一、数据库,表,字段编码格式都为latin1(iso-8859-1) 。当数据保存到数据库后,中文显示乱码。
解决办法:
1.在访问数据库连接串中添加编码格式:
<add key="MySqlConnectionString" value="Server=127.0.0.1;Port=3306;Uid=ttt;Pwd=ttt;Database=test_db;innercharacterset=gb2312;charset=gb2312" />
获取出来的中文信息没有问题。
注意:使用gb2312编码添加的中文信息,读取时也要使用相同编码格式,也就是存取的编码格式要一致;否则获取出来为乱码。
二、若获取的字符串为Latin1编码,在C#中可以做如下转换:
/// <summary>
/// Latin1(iso-8859-1) 转 gb2312 中文
/// </summary>
/// <param name="str"></param>
/// <returns></returns>
public static string Latin1ToUtf8( string str) {
//这里的 gb2312 取决于 mysql连接字符串中设定的字符编码。
return Encoding.GetEncoding("gb2312").GetString(Encoding.GetEncoding("ISO-8859-1").GetBytes(str));
}
MySQL 表与字段编码格式报错的更多相关文章
- Mysql表创建外键报错
数据库表A: CREATE TABLE task_desc_tab ( id INT(11) PRIMARY KEY NOT NULL COMMENT '自增主键' AUTO_INCREMENT, t ...
- Sqoop- sqoop将mysql数据表导入到hive报错
sqoop将mysql数据表导入到hive报错 [root@ip---- lib]# sqoop import --connect jdbc:mysql://54.223.175.12:3308/gx ...
- 在给mysql数据库备份时,报错: mysqldump: Got error: 145: Table '.\shengdaxcom\pre_forum_thread' is marked as c rashed and should be repaired when using LOCK TABLES
在给mysql数据库备份时,报错: mysqldump: Got error: 145: Table '.\shengdaxcom\pre_forum_thread' is marked as cra ...
- DB2读取CLOB字段-was报错:操作无效:已关闭 Lob。 ERRORCODE=-4470, SQLSTATE=null
DB2读取CLOB字段-was报错:操作无效:已关闭 Lob. ERRORCODE=-4470, SQLSTATE=null 解决方法,在WAS中要用的数据源里面配置连个定制属性: progressi ...
- egg 连接 mysql 的 docker 容器,报错:Client does not support authentication protocol requested by server; consider upgrading MySQL client
egg 连接 mysql 的 docker 容器,报错:Client does not support authentication protocol requested by server; con ...
- MySql表、字段、库的字符集修改及查看方法
这篇文章主要介绍了MySql表.字段.库的字符集修改及查看方法,本文分别给们它的修改及查看语句,需要的朋友可以参考下 修改数据库字符集: 代码如下: ALTER DATABASE db_name DE ...
- ES使用text类型字段排序报错
elasticsearch text字段排序报错解决使用elasticsearch 进行排序的时候,我们一般都会排序数字.日期.但是在排序text类型的时候就会出现错误. GET xytest/sut ...
- mysql 中modify和change区别(以及使用modify修改字段名称报错)
使用modify修改字段报错如下: mysql> alter table student modify name sname char(16);ERROR 1064 (42000): You h ...
- mysql|full join 多表联查,系统报错,无法解答!
查询语句: select 分数 from cfull join don c.姓名=d.姓名 报错: [Err] 1054 - Unknown column 'c.姓名' in 'on clause' ...
随机推荐
- SQL: enable sa Account in SQL Server
Link: http://sudeeptaganguly.wordpress.com/2010/04/20/how-to-enable-sa-account-in-sql-server/ 引用: Wh ...
- Android ListView item项 显示动画
(1)使用LayoutAnimation 所谓的布局动画,其实就是为ViewGroup添加显示动画效果,主要用过LayoutAnimationController来控制实现.LayoutAnimati ...
- [Leetcode] Interleaving String
Given s1, s2, s3, find whether s3 is formed by the interleaving of s1 and s2. For example,Given:s1 = ...
- 【BZOJ】3456: 城市规划
http://www.lydsy.com/JudgeOnline/problem.php?id=3456 题意:求n个点的无向连通图的方案.(n<=130000) #include <bi ...
- 【BZOJ】3434: [Wc2014]时空穿梭
http://www.lydsy.com/JudgeOnline/problem.php?id=3434 题意:n维坐标中要找c个点使得c个点在一条线上且每一维的坐标单调递增且不能超过每一维限定的值m ...
- [BZOJ2793][Poi2012]Vouchers
2793: [Poi2012]Vouchers Time Limit: 20 Sec Memory Limit: 64 MBSubmit: 316 Solved: 148[Submit][Stat ...
- C#_生成HTML
#region 生成静态页 /// <summary> /// 生成静态页 /// </summary> /// <param name="URL"& ...
- 关于webdriver中弹出框的定位
对于webdriver中弹出框的定位,需要引入这个包: import org.openqa.selenium.Alert; 具体语句为: Alert alert= driver.switchTo(). ...
- 所有设备的CSS像素
mydevice.io Mobile devices, in Responsive Web Design, relate to a core value which is the value of C ...
- 本地数据库(SQL Server)远程连接服务器端服务器
本地数据库(SQL Server 2012) 连接外网服务器的数据库,外网的服务器端需要做如下配置: 1. 首先是要打开 数据的配置管理工具 2. 配置相关的客户端协议,开启TCP/IP 3. 数据库 ...