How to retrieve unicode data stored directly in non-unicode field as varchar format in sql server

我怕爱的太早我们不能终老 提交于 2019-12-25 04:53:37

问题


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

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.


回答1:


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.




回答2:


You could try reading the data cast as varbinary(...) out of sql server and then create your own StreamReader in C# specifying the encoding. You'll need to know how the data is encoded though as there are 5 standard unicode encodings available in .NET.



来源:https://stackoverflow.com/questions/2721964/how-to-retrieve-unicode-data-stored-directly-in-non-unicode-field-as-varchar-for

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!