Oracle character conversion (of non ASCII values?) with DataAdapter

  • Thread starter Thread starter Håkan Garneij
  • Start date Start date
H

Håkan Garneij

Hi all,

I get strange character conversions when fetching CLOB fields in Oracle 8i.
When looking at the data in the database with TOAD the characters seem to be
correctly stored.

The character ''' when fetched is represented by a square (unknown?) in a
string type in C#.
The int value for this character is supposedly 65533 but I don't think this
value is correct either since that is too big for a char.

Can any parameters to the connectionstring fix this?

I'm using the following sample connectionstring:
Data Source=oracle8;User ID=scott;Password=tiger;Pooling='false';


Code sample:

....

DataSet oDs = new DataSet();
OracleDataAdapter oDa = new OracleDataAdapter( String.Format( SQL,
parameters), oConnection ) ;
oDa.Fill( oDs );

....

foreach ( DataRow oDr in oDs.Tables[0].Rows )
sLongText = oDr["LongText"].ToString();

....


Regards
Håkan
 
Can any parameters to the connectionstring fix this? NO. Not a connection issue its a data format/conversion issue, because you've given it a DataSet with the incorrect local for serialized data

Try seting your locale on the DataSet like this
oDs.Locale = CultureInfo.InvariantCulture

Full details see text below fix of your code snippe

Peter Evans (__PETER Peter_

[snip]
DataSet oDs = new DataSet()
--> oDs.Locale = CultureInfo.InvariantCulture

OracleDataAdapter oDa = new OracleDataAdapter( String.Format( SQL
parameters), oConnection )
oDa.Fill( oDs )
[snip]

_________
From GoTDotNet.com
http://www.gotdotnet.com/team/fxcop....aspx?url=Globalization/LocaleShouldBeSet.htm

The Locale property should be set for most DataSet and DataTable instance
Message Level: Error
Certainty: 90%
Type: LocaleShouldBeSetForDataTypes

Cause: A method or constructor created one or more System.Data.DataTable or System.Data.DataSet instances and did not explicitly set the locale property (System.Data.DataTable.Locale or System.Data.DataSet.Locale)

Rule Description
The locale determines culture-specific presentation elements for data, such as formatting used for numeric values, currency symbols, and sort order. When you create a DataTable or DataSet, you should set the locale explicitly. By default, the locale for these types is the current culture. For data that is stored in a database or file and is shared globally, the locale should normally be set to the invariant culture (System.Globalization.CultureInfo.InvariantCulture). When data is shared across cultures, using the default locale can cause the contents of the DataTable or DataSet to be presented or interpreted incorrectly
 
Sorry, a bit late, but .. THANK YOU!!! With bells on ..:D

Regards
Håkan Garneij
 
Last edited:
Back
Top