I am using a generic approach to receiving a single row from any Oracle table and displaying it in a datagridview, using the code below. But, if the table contains a column of float type and the value has a large number of decimal places, I get “Arithmetic operation resulted in an overflow” at the line: MyReader.GetValues(objCells);
oCmd.CommandText = "OTCMIADM.OTCMI_GUI.GET_ROW";
oCmd.CommandType = CommandType.StoredProcedure;
oCmd.Parameters.Add("PI_TABLE_NAME", OracleDbType.Varchar2, 40).Value = cmbStagingTables.SelectedItem;
oCmd.Parameters.Add("PI_ROWID", OracleDbType.Varchar2, 40).Value = txtRowID.Text;
oCmd.Parameters.Add(new OracleParameter("PIO_CURSOR", OracleDbType.RefCursor)).Direction = ParameterDirection.Output;
oCmd.ExecuteNonQuery();
// clear the datagrid in preperation for loading
dgvStagingTable.Columns.Clear();
dgvStagingTable.Rows.Clear();
using (OracleDataReader MyReader = oCmd.ExecuteReader())
{
int ColumnCount = MyReader.FieldCount;
// add the column headers
DataGridViewColumn[] columns = new DataGridViewColumn[ColumnCount];
for (int i = 0; i < columns.Length; ++i)
{
DataGridViewColumn column = new DataGridViewTextBoxColumn();
column.FillWeight = 1;
column.HeaderText = MyReader.GetName(i);
column.Name = MyReader.GetName(i);
columns[i] = column;
}
dgvStagingTable.Columns.AddRange(columns);
// get the data and add the row
while (MyReader.Read())
{
//get all row values into an array
object[] objCells = new object[ColumnCount];
MyReader.GetValues(objCells);
//add array as a row to grid
dgvStagingTable.Rows.Add(objCells);
}
}
The stack trace shows:
at Oracle.DataAccess.Types.DecimalConv.GetDecimal(IntPtr numCtx)
at Oracle.DataAccess.Client.OracleDataReader.GetDecimal(Int32 i)
at Oracle.DataAccess.Client.OracleDataReader.GetValue(Int32 i)
at Oracle.DataAccess.Client.OracleDataReader.GetValues(Object[] values)
So I can see why it’s causing an error (it’s assuming a decimal conversion); but how do I get round this?
I tried explicitly setting the type of the column before loading the data with:
dgvStagingTable.Columns[“TR_THROUGHPUT_TIME_NO”].ValueType = typeof(string);
and several other typeofs, but nothing made any difference.
Any help appreciated.
I initially suggested using OracleDbTypeEx (http://download.oracle.com/docs/html/E15167_01/OracleParameterClass.htm#CHDJHDGE) to fix this for you, this was wrong so this is a new suggestion.
so what I did:
Now this will get some data known to be beyond .net.
then the .net side:
This converts everything to string but it’ll work.
http://download-east.oracle.com/docs/html/A96160_01/features.htm#1048038
I just looked over your initial query once again, you are calling the query twice:
you don’t need the ExecuteNonQuery; the ExecuteReader executes the sp