How to output chinese charactes from SQL database correctly in VB.NET
I have a nvarchar(256) field in a SQL 2005 database table that contains several records in Chinese and I'd like to output this characters 开发者_Python百科correctly in VB.NET code.
What I have now doesn't work at all:
Dim MyText As String = "推荐评论: 属于那~种类型的电影"
Dim value As [String] = MyText
Dim tc As Encoding = Encoding.GetEncoding(950)
Dim bytes As Byte() = tc.GetBytes(value)
value = Encoding.Unicode.GetString(bytes)
Console.WriteLine(value + vbCrLf)
MyText string is the Chinese language coming from the db field so no problems there. My problem is how to display "MyText" correctly. What is the right way to do this? I'm using a simple console app to do the test.
Thanks.
It's not easy to get console applications to correctly display unicode characters. You will find it much easier to write a WinForms application instead.
精彩评论