Samujjal
Samujjal

Reputation: 11

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

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.

Upvotes: 0

Views: 1246

Answers (2)

Thomas
Thomas

Reputation: 64674

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.

Upvotes: 1

Daniel Renshaw
Daniel Renshaw

Reputation: 34187

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.

Upvotes: 0

Related Questions