Problem with OracleGlobalization

Problem with OracleGlobalization

Postby bi_wolf » Thu 16 Dec 2010 18:04

Hello,

I have a file with all data I have to insert in the database. For different reason my programm save the data read into a string.
Even if I use OracleGlobalization I have a problem when I have to insert numbers which they are under 1000 because in the file (so in my string) the data is 1,200.0 for 1200 :cry:
Does anabody have a solution or an idea ?

The Oracle exception is : "String format incorrect"
Thanks
bi_wolf
 
Posts: 2
Joined: Thu 16 Dec 2010 16:49

Postby Shalex » Mon 20 Dec 2010 17:04

You should set the OracleGlobalization.NumericCharacters property to the corresponding NLS_NUMERIC_CHARACTERS value. I can insert 1,200.0 in my database with the following code:
Code: Select all
//DDL:
//CREATE TABLE SCOTT.NUMBER_TABLE (
//  NUMBER_COLUMN NUMBER(38, 9));

    using (OracleConnection conn = new OracleConnection()) {
        conn.ConnectionString = "server=orcl1120;uid=scott;pwd=tiger;";

        OracleGlobalization glob = OracleGlobalization.GetApplicationInfo();
        glob.NumericCharacters = ".,";
        OracleGlobalization.SetApplicationInfo(glob);

        conn.Open();
        OracleCommand cmd = conn.CreateCommand();
        cmd.CommandText = "insert into number_table values (:p)";
        cmd.Parameters.Add("p", OracleDbType.Number).Value = "1,200.0";
        cmd.ExecuteNonQuery();
    }

Documentation:
http://www.devart.com/dotconnect/oracle/docs/?Devart.Data.Oracle~Devart.Data.Oracle.OracleGlobalization~NumericCharacters.html
http://download.oracle.com/docs/cd/B28359_01/olap.111/b28126/dml_options072.htm

Notify us about the results.
Shalex
Devart Team
 
Posts: 7527
Joined: Thu 14 Aug 2008 12:44

Postby bi_wolf » Tue 21 Dec 2010 10:57

I checked parameters of my database and NLS_NUMERIC_CHARACTERS is good :
Code: Select all
NLS_NUMERIC_CHARACTERS   .,


I used devArt.Oracle 5.70.170.0 and I test exactly your code but I have already an exception :
The input format is incorrect


I downloaded the version 6.0 and it works fine.
So all is good now.

Thanks
bi_wolf
 
Posts: 2
Joined: Thu 16 Dec 2010 16:49

Postby Shalex » Wed 22 Dec 2010 09:54

The Devart.Data.Oracle.OracleGlobalization class manages the Oracle globalization settings of the application, and local computer (but not the server's one). I have posted the http://download.oracle.com/docs/cd/B28359_01/olap.111/b28126/dml_options072.htm reference to show the correct syntax for the OracleGlobalization.NumericCharacters property.
Shalex
Devart Team
 
Posts: 7527
Joined: Thu 14 Aug 2008 12:44


Return to dotConnect for Oracle