Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET VB.NET
Hi,
 
I am trying to read Swedish characters from the database and display them on my ASP.NET page. However the data is not read correctly from the Database.
Eg.
Café.
is read as
Café.
ö is read as ö
 
I am using 3 tier architecture and below is the code I used to get the values in a dataset:
Public Function GetDataSetProc(ByVal strSql As String) As DataSet
       Return GetDataSetProc(strSql, DirectCast(Nothing, OleDbParameter()))
   End Function
 

   Public Function GetDataSetProc(ByVal strSql As String, ByVal arProcParams As OleDbParameter()) As DataSet
       Dim dataSet As New DataSet()
       Try
           OpenDBConnection()
           dataCom.CommandText = strSql
           dataCom.CommandTimeout = 1000
           dataCom.Parameters.Clear()
           dataAdp.SelectCommand = dataCom
 
           If arProcParams IsNot Nothing Then
               For Each param As OleDbParameter In arProcParams
                   dataCom.Parameters.Add(param)
               Next
           End If
           dataAdp.Fill(DataSet)
           dataCon.Close()
 
       Catch ex As Exception
           WriteToLog(ex.Message.ToString())
       End Try
       Return DataSet
 
   End Function
 
KIndly help me read the data from the database in a correct way !!!!!
 
Thanks in Advance Smile | :)
Posted 6-Nov-12 19:30pm

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Use text SQL data types supporting Unicode, such as nchar, nvarchar, and ntext, instead of char, varchar, and text.
 
Please see: http://msdn.microsoft.com/en-us/library/ms191200%28v=sql.105%29.aspx[^].
 
—SA
  Permalink  
Comments
MikeRox89 at 7-Nov-12 3:37am
   
Hi Sergey,I am not supposed to change the oracle code.
 
After getting the value in dataset, I can write the following code:
 
str = Encoding.UTF8.GetString(Encoding.GetEncoding(1252).GetBytes(STRING_TO_BE_CONVERTED))
 
However the problem is that I'll have to write this code in all the pages in code-behind.
 
Hence I'm looking an alternate way so that the data in dataset is retrieved correctly in the DATA Layer itself and I dont have to change any code in code-behind in all the pages.
Sergey Alexandrovich Kryukov at 7-Nov-12 12:47pm
   
If so, you are pretty much screwed up. Still, it's possible that things could be fixed if your database encoding is consistent. Are you 100% sure your encoding is 1252? Why then do you mess with UTF8? That could be a problem. Please explain what's the purpose of this line. Or, what is STRING_TO_BE_CONVERTED? (Internal Unicode representation in Windows is UTF-16L.)
--SA
MikeRox89 at 8-Nov-12 0:41am
   
When I read database values in the dataset, the data I recieve in the dataset is wrong.
Café becomes Café in the dataset itself.
 
I use the below code to convert Café back to Café in every page before I use the data.

str = Encoding.UTF8.GetString(Encoding.GetEncoding(1252).GetBytes(Café))
 
I'm trying a way to retrieve the data correctly in the database itself.
Please Help me if you have a solution to this.
Sergey Alexandrovich Kryukov at 8-Nov-12 1:34am
   
Without modifying of the data in database? You already do the "fix"... this is ridiculous though. You tell me "fix it, but not touch anything", don't you?
--SA
MikeRox89 at 8-Nov-12 23:48pm
   
The data in database is already correct, i.e. Café. When I read the data from database into a dataset in asp.net, the data is not retrieved correctly, i.e. it shows Café.(which is incorrect). I need to retrieve the correct data in the dataset, i.e. it should come into the dataset as Café, which is also the value present in the database.. Can you plz help me with this ??
Sergey Alexandrovich Kryukov at 9-Nov-12 0:15am
   
Here is the problem then. You are not showing in what sense it is correct or not, because you mix up the content with presentation (interpretation) of data. Are you getting the point? In certain sense, Café is also "correct", because it can be interpreted correctly. Therefore, you need to show what is in database and after all your steps in bytes. Obtain bytes on each steps (in your expression, you already have them) and provide bytes. On this site, it's already shown in UTF-8 and blocks the vision of what's inside.
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



Advertise | Privacy | Mobile
Web01 | 2.8.141022.2 | Last Updated 7 Nov 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100