English 中文(简体)
从 MySql (ASP.NET) 读取 yrillic
原标题:Read cyrillic from MySql (ASP.NET)

我有张MySqlDB和一张桌子

CREATE TABLE `pp` (
[...]
`Title` varchar(255) CHARACTER SET latin1 DEFAULT NULL,
[...]
) ENGINE=InnoDB DEFAULT CHARSET=cp1251 

该表由 PHP 组成, 并有一个工作 PHP 脚本读取数据并将其写入网页。 PHP 使用“ windows-1251” 编码并正常工作 。

服务器侧的变量为:

character_set_client:latin1
character_set_connection:latin1
character_set_database:utf8
character_set_filesystem:binary
character_set_results:latin1
character_set_server:latin1
character_set_system:utf8

I am working on an ASP.NET MVC3 application that (among other things) reads that data and shows them in a windows-1251 encoded view. I use MySql .NET Connector v.6.5.4 to connect to DB and read data.

问题在于:由此形成的网页(即视图)上的闪烁数据被损坏。

我尝试了各种连接线

charset=cp1251   or
charset=latin1   or
charset=utf8     

此外,我还研究过执行

SET NAMES cp1251   or 
SET NAMES latin1   or 
SET NAMES utf8      

在连接之后,但没有任何成功。

在PHP中,一切都很好;在ASP.NET中,情况并非如此。

我知道闪石文字不应该存储在 拉丁一列中, PHP 工作正常, 因为 cp1251 和 latin1 是 8 位/ 每字符编码, 没有数据转换 。 但我无法使用 ASP. NET 复制它 。

请救救我

问题回答

1 将字段字符集更改为 cp1251 或 utf8, 例如 -

ALTER TABLE `pp`
  CHANGE COLUMN `Title` `Title` VARCHAR(255) CHARACTER SET cp1251 COLLATE cp1251_general_ci DEFAULT NULL;

2 在插入或选择连接字符集之前设置

SET NAMES cp1251;

SET NAMES utf8;




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签