0

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.

Samujjal
  • 11
  • 3

2 Answers2

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.

Thomas
  • 63,911
  • 12
  • 95
  • 141
  • You may also need to continue to write to the varchar column as well until you can change the dependent applications to the new column. Once all have been converted, then drop the varchar column. – HLGEM Apr 27 '10 at 15:15
  • @HLGEM - An interesting question would be "write what?". If the value is in Unicode, it may not be convertible to the given column's collation. – Thomas Apr 27 '10 at 15:24
  • You may need to copy what you can whcih would be simliar to how the dat stands now. Otherwise the other applications would be missing the information they need until they are converted to the new column. This is no worse than the current situation and likely the majority of the records are readable. And if the data is a bit strange, well that just gives the legacy applications reasons to adjust to using the new column. – HLGEM Apr 27 '10 at 17:34
0

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.

Daniel Renshaw
  • 33,729
  • 8
  • 75
  • 94