Click here to Skip to main content
12,898,174 members (69,137 online)
Rate this:
Please Sign up or sign in to vote.

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.

is read as

ö 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()
           dataCom.CommandText = strSql
           dataCom.CommandTimeout = 1000
           dataAdp.SelectCommand = dataCom
           If arProcParams IsNot Nothing Then
               For Each param As OleDbParameter In arProcParams
           End If
       Catch ex As Exception
       End Try
       Return DataSet
   End Function

KIndly help me read the data from the database in a correct way !!!!!

Thanks in Advance :)
Posted 6-Nov-12 19:30pm

1 solution

Rate this: bad
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:[^].

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.
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.)
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.
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?
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, 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 ??
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.

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

    Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170424.1 | Last Updated 7 Nov 2012
Copyright © CodeProject, 1999-2017
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