R
Rob
Hello all
I have a SQL Server database and I'm experiening terrible problems in
displaying japanese language text stored in the db in my
ado.net/asp.net application. The relevant columns in the db are all
nvarchar (thus unicode).After pulling the data and using the
ToString() method alone always results in garbage on the screen,
regardless of what encloding is selected in the browser
(view-encoding) or what culture threads I set up - for example:
Thread.CurrentThread.CurrentCulture = new CultureInfo("ja-JP");
The only way I have been able to get the correct display is to convert
the encoding to shift_jis like this:
// rdr is an instance of SqlDataReader
string uniString = rdr["blahblah"].ToString();
Response.Write(uniString); // outputs garbage
// 1252 is the default codepage, and 932 is the shift_jis codepage
byte[] bytes = Encoding.GetEncoding(1252).GetBytes(uniString);
Response.Write(Encoding.GetEncoding(932).GetString(bytes)); // no
problem
In addition to culture, I have also tried this in web.config:
<globalization requestEncoding="shift_jis"
responseEncoding="shift_jis" fileEncoding="shift_jis" />
The result is also the same if I use englishXP/englishIE or
japaneseXP/japaneseIE as the client OS/browser.
Is there some other way to get the desired output ? Although the above
solution works for simple output using a reader, it doesn't seem very
elegant and when I want to use a dataset and bind it to a control I am
back at square one.
Any help / advice is much appreciated
Thanks
Rob
I have a SQL Server database and I'm experiening terrible problems in
displaying japanese language text stored in the db in my
ado.net/asp.net application. The relevant columns in the db are all
nvarchar (thus unicode).After pulling the data and using the
ToString() method alone always results in garbage on the screen,
regardless of what encloding is selected in the browser
(view-encoding) or what culture threads I set up - for example:
Thread.CurrentThread.CurrentCulture = new CultureInfo("ja-JP");
The only way I have been able to get the correct display is to convert
the encoding to shift_jis like this:
// rdr is an instance of SqlDataReader
string uniString = rdr["blahblah"].ToString();
Response.Write(uniString); // outputs garbage
// 1252 is the default codepage, and 932 is the shift_jis codepage
byte[] bytes = Encoding.GetEncoding(1252).GetBytes(uniString);
Response.Write(Encoding.GetEncoding(932).GetString(bytes)); // no
problem
In addition to culture, I have also tried this in web.config:
<globalization requestEncoding="shift_jis"
responseEncoding="shift_jis" fileEncoding="shift_jis" />
The result is also the same if I use englishXP/englishIE or
japaneseXP/japaneseIE as the client OS/browser.
Is there some other way to get the desired output ? Although the above
solution works for simple output using a reader, it doesn't seem very
elegant and when I want to use a dataset and bind it to a control I am
back at square one.
Any help / advice is much appreciated
Thanks
Rob