如何在SQL Server中检索以varchar格式直接存储在非unicode字段中的unicode数据 [英] How to retrieve unicode data stored directly in non-unicode field as varchar format in sql server

查看:164
本文介绍了如何在SQL Server中检索以varchar格式直接存储在非unicode字段中的unicode数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须创建一个C#应用程序,以在文本框中显示unicode数据。

I have to create a C# application which displays unicode data in a textbox.

但是SQL Server列存储具有包含unicode数据的varchar数据。但是由于varchar是基于非Unicode的,因此会显示诸如 ????????之类的字符串。

But the SQL server column storage has varchar data which contains unicode data. But since varchar is non-unicode based it displays character strings like "????????".

我面临的问题是我无法更改列类型,因为正在运行其他依赖应用程序。

Well the problem i am facing is i cant change the column type as there are other dependent application running on it.

推荐答案

您无法将Unicode数据存储在 varchar中,而无需转换为列的排序规则。因此,当Unicode编码存储在 varchar 列中并且可能丢失时,其编码方式将完全不同。如果看到 ????? ,则表示编码在存储时找不到映射到ANSI值的字符,并且存储了问号代替。如果要将Unicode存储在数据库中,正确的解决方案是更改列的数据类型。如果您无法更改列的数据类型,则将列设置为 nvarchar ,并确保您的Unicode源可以读写该列。

You cannot store Unicode data in varchar without a conversion to the column's collation. So, what was Unicode will be encoded entirely different when it is stored in a varchar column and probably lost. If you are seeing ????? then it means that the encoding could not find a character that maps to the ANSI value when it was being stored and it stored a question mark instead. If you want to store Unicode in the database the right solution is to change the column's data type. If you cannot change the column's data type, then add a column set to nvarchar and ensure your Unicode sources read and write to that column.

这篇关于如何在SQL Server中检索以varchar格式直接存储在非unicode字段中的unicode数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆