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' ...
随机推荐
- 《HBase实战》
对,我正在研读这本书,今天开始,我希望我看完后能有收获和大家分享,这个日志作为开始,勉励自己! 对,我应该静下心,做一些我更喜欢的事情,不能在自我陶醉中迷失! 断断续的看,到今天大概把这本书看完了,没 ...
- js公有、私有、静态属性和方法的区别
现下,javascript大行其道,对于网站开发人员来说,javascript是必需掌据的一门语言,但随着jquery等框架的流行和使用,许多人对于原生javascript缺乏深入的理解, ...
- NUC_HomeWork1 -- POJ2067(最短路)
C - Fire Station Description A city is served by a number of fire stations. Some residents have comp ...
- CF# 334 Alternative Thinking
A. Alternative Thinking time limit per test 2 seconds memory limit per test 256 megabytes input stan ...
- linux建立ssh信任关系
一.建立SSH信任将A主机做为客户端(发起SSH请求 ip:192.168.200.170)将B主机作为服务器端(接收ssh请求 ip:192.168.200.149)以上以主动发起SSH登录请求 ...
- 《深入浅出Windows 10通用应用开发》
<深入浅出Windows 10通用应用开发>采用Windows 10的SDK进行重新改版,整合了<深入浅出Windows Phone 8.1应用开发>和<深入解析 ...
- Code[VS]1690 开关灯 题解
Code[VS]1690 开关灯 题解 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 钻石 Diamond 题目描述 Description: YYX家门前 ...
- nohup命令浅析
要将一个命令放到后台执行,我们一般使用nohup sh command & &都知道是放到后台执行这个命令,那么nohup是做什么的? 这就要从unix的信号说起,unix的信号机制可 ...
- Nodejs操作redis
//npm install redis //首先加载node_redis模块 var redis = require('redis'); // 创建redis连接 var client = redis ...
- find命令详解
find命令详解 来源: ChinaUnix博客 日期: 2008.07.25 16:04 (共有条评论) 我要评论 [url=http://www.sudu.cn/web/host.php] ...