Due to reasons, we're having to transform our code to get DB2 data through an Odbc connection instead of OleDb. But we're having some difficulties with DECIMAL types.
We're calling a stored procedure on DB2 and filling the data in a DataSet using an OdbcDataAdapter. The procedure in the DB2 database returns a DECIMAL(5,2) with the value 100.00 but in the DataSet the value is 10000 (the point seperator is gone).
This was not an issue when we were using the OleDb driver, but we have to use Odbc now. We're using the IBM DB2 ODBC DRIVER which is installed with the full IBM DB2 client (11.5.7.0).
I've read that using OdbcDataReader.GetDouble() would fix this, but it would be a lot of work to transform all our code to use DataReaders instead of DataAdapters. The SP also returns multiple result sets, so the DataSet is easier to use.
Here's a summized form of our code:
// ...
using (System.Data.Odbc.OdbcConnection db2Conn = new System.Data.Odbc.OdbcConnection(connStringDB2))
{
OdbcCommand cmdDB2 = new OdbcCommand();
cmdDB2.CommandText = "call SP()";
cmdDB2.CommandType = System.Data.CommandType.StoredProcedure;
cmdDB2.Connection = db2Conn;
cmdDB2.CommandTimeout = 1800;
dsDB2 = new DataSet();
OdbcDataAdapter daDB2 = new OdbcDataAdapter(cmdDB2);
daDB2.Fill(dsDB2);
db2Conn.Close();
}
// ...
// We're opening a connection to our SQL Server database to push the data of the DB2 procedure to
// All the result sets are visited as shown below
// ...
foreach (DataRow dr in dsDB2.Tables[8].Rows)
{
cmdSql.Parameters["@Name"].Value = dr["name"];
cmdSql.Parameters["@Value"].Value = dr["value"];
cmdSql.Parameters["@Percentage"].Value = dr["percentage"]; // here there's a mismatch with the DECIMAL(5,2) value 100.00, which is given as 10000
cmdSql.ExecuteNonQuery();
}
// ...