Read Chinese Character from SQL(SQL Server 2005) Database Table Column and Display Chinese Character , csharp Hong Kong SAR
  • 12 years ago

    I have a table like this below and it doesn't only contain English Names but it also contain Chinese Name.
    (FirstName NVARCHAR (50),
    LastName NVARCHAR (50));
    I tried to view the column using SQL Query Analyzer, It didn't display Chinese Character.
    I know that SQL Server 2005 is using UCS-2 Encoding and Chinese Character uses Double Byte Character Set (DBCS) Encoding.
    I want to read the FirstName and LastName columns and display in Window Form Data Grid and ASP.NET Grid View.
    I tried to use this code below and it didn't work. It convert some of the English Name to Chinese Character and it display the chinese character and some still in the original unreadable characters.
    Does anybody know how to read those character from SQL Table and display the correct Chinese Character without converting the English Name into Chinese also?

    int codePage = 950;
    StringBuilder message = new StringBuilder();
    Encoding targetEncoding = Encoding.GetEncoding(codePage);
    byte[] encodedChars= targetEncoding.GetBytes(str);
    message.AppendLine("Byte representation of '" + str + "' in Code Page '" + codePage + "':");
    for (int i = 0; i < encodedChars.Length; i++)
    message.Append("Byte " + i + ": " + encodedChars[i]);

    message.AppendLine(" RESULT : " + System.Text.Encoding.Unicode.GetString(encodedChars));

Post a reply

No one has replied yet! Why not be the first?

Sign in or Join us (it's free).


Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Linux is only free if your time has no value” - Jamie Zawinski