Rounding off numeric data while using SqlBulkCopy in C#

c# oracle11g sqlbulkcopy sql-server

Question

I am using SqlBulkCopy to import data from Oracle 11g source to MS SQL Server 2012. But one of the NUMERIC columns in Oracle contains values like 53682.0(~35times)1, 263.9(~32times). The target column in Sql Server is currently a FLOAT datatype and currently I am getting the following Exception:

Arithmetic operation resulted in an overflow.

This is my sample code:

using (SqlConnection conn = new SqlConnection(destConnString))
        {
            conn.Open();
            try
            {
                using (OracleConnection connection = new OracleConnection(srcConnString))
                {
                    using (OracleCommand command = new OracleCommand(selectQuery, connection))
                    {
                        connection.Open();
                        using (OracleDataReader reader = command.ExecuteReader(CommandBehavior.Default))
                        {
                            using (SqlBulkCopy bulkCopy = new SqlBulkCopy(conn, SqlBulkCopyOptions.KeepIdentity, trans))
                            {
                                bulkCopy.DestinationTableName = tableName;
                                bulkCopy.BulkCopyTimeout = 0;
                                bulkCopy.WriteToServer(reader);
                            }
                        }
                    }
                }
                trans.Commit();
            }
            ....

I am trying to round-off this data but with no success, also I cannot change anything in Oracle table.

Accepted Answer

Can't you just modify your Oracle SELECT query, e.g. to truncate the offending numeric value?




Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why