|
.net
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Cannot display Chinese data from databaseI tried to display the data in an aspx but the characters cannot display correctly. I tried anything I think is related: - Setting the charset, codepage of the page - changed the responseEncoding in web.config to Big5 - hardcoded Response.ContentEncoding to 950 (codepage of Big5) - Change the file encoding to Big5 (in save option) None of them work. For the same data, it can displayed correctly in my classic asp. Code (.NET) private void Page_Load(object sender, System.EventArgs e) { SqlConnection connection = new SqlConnection(ConfigurationSettings.AppSettings["NewsDB"]); SqlCommand command = new SqlCommand(); command.Connection = connection; command.CommandText = "SELECT Newsid, StoryDate, StoryTime, Headline FROM tblLatestHeader"; command.CommandType = CommandType.Text; SqlDataReader dataReader; connection.Open(); dataReader = command.ExecuteReader(); string html = ""; while (dataReader.Read()) { html += dataReader[3].ToString(); } connection.Close(); Label1.Text = html; Label2.Text = "ä½ å¥½å—Ž"; // this is chinese character which can display correctly } Work in classic asp: <% Set connection = Server.CreateObject("ADODB.Connection") connection.ConnectionString = "Provider=sqloledb;Data Source=MyDB;Initial Catalog=NewsDB;User Id=sa;Password=fakepwd;" connection.open Set rs = connection.execute("SELECT Newsid, StoryDate, StoryTime, Headline FROM tblLatestHeader") While Not rs.eof response.write rs("Headline") & "<br>" rs.movenextwend %> Jason Chan wrote:
> Some chinese characters data (in Big5 encoding) is stored in database. The Codepage directive in ASP.NET 2.0 is the same as reponseEncoding in> I tried to display the data in an aspx but the characters cannot > display correctly. > I tried anything I think is related: > - Setting the charset, codepage of the page web.config. > - changed the responseEncoding in web.config to Big5 And these are identical as well (the latter, like Codepage, works at> - hardcoded Response.ContentEncoding to 950 (codepage of Big5) the page level though). > - Change the file encoding to Big5 (in save option) That's only relevant at buildtime.Show quoteHide quote > None of them work. If your hardcoded sample text is displayed correctly, there's quite> > For the same data, it can displayed correctly in my classic asp. > > Code (.NET) > private void Page_Load(object sender, System.EventArgs e) > { > SqlConnection connection = new > SqlConnection(ConfigurationSettings.AppSettings["NewsDB"]); > SqlCommand command = new SqlCommand(); > command.Connection = connection; > command.CommandText = "SELECT Newsid, StoryDate, StoryTime, > Headline FROM tblLatestHeader"; > command.CommandType = CommandType.Text; > > SqlDataReader dataReader; > connection.Open(); > dataReader = command.ExecuteReader(); > string html = ""; > while (dataReader.Read()) > { > html += dataReader[3].ToString(); > } > connection.Close(); > Label1.Text = html; > Label2.Text = "ä½ å¥½å—Ž"; // this is chinese character which > can display correctly > } likely a problem with your ADO.NET provider. Are the correct characters displayed when you debug your code right after retrieving strings from the database? Cheers,
Other interesting topics
How to add a small HTML table under a row of a GridView
Visual Web Developer Express How do I build Code-behind into DLL in bin folder Application["TotalPlayings"]++ doesn't work Source Control Products??? Downloading file from database ASP classic -> ASP.NET 2.0 A translatable website Problem Running ASP.NET/ASP App Under VS 2005 Cannot POST to .XML page specifying a query string in an href dynamically |
|||||||||||||||||||||||