问题
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