Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.
VB
Café.

is read as
VB
Café.

ö is read as ö

I am using 3 tier architecture and below is the code I used to get the values in a dataset:
VB
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 :)
Posted

1 solution

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
 
Share this answer
 
Comments
MikeRox89 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 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 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 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 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 ??

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900