Click here to Skip to main content
15,887,135 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I want to fetch the output parameter of numeric data type from Oledb in c#. I am connecting to Oledb database and calling one stored procedure. I am getting implicit conversion of numeric field exception while fetching the same.
ItemId = Convert.ToInt32(DbCmd.Parameters["@op_item_id"].Value);

What I have tried:

My code is as below:
C#
  OleDbCommand DbCmd = new OleDbCommand("asp_DDA_add", objSybaseDataAccessBase.Connection);
                DbCmd.CommandType = CommandType.StoredProcedure;
                DbCmd.CommandTimeout = 600;
                DbCmd.Parameters.Add(objSybaseDataAccessBase.SetParameter("@ip_acct_no", Accountno, ParameterDirection.Input, 100, OleDbType.VarChar));
                              DbCmd.Parameters.Add(objSybaseDataAccessBase.SetParameter("@ip_expiry_dt_block", BlockExpiryDate, ParameterDirection.Input, 1000, OleDbType.DBTimeStamp));
                DbCmd.Parameters.Add(objSybaseDataAccessBase.SetParameter("@ip_user_name", Sybase_User, ParameterDirection.Input, 1000, OleDbType.VarChar));
                DbCmd.Parameters.Add(objSybaseDataAccessBase.SetParameter("@op_error_code", strErrorCode, ParameterDirection.Output, 1000, OleDbType.Integer));
                DbCmd.Parameters.Add(objSybaseDataAccessBase.SetParameter("@op_error_msg", strErrorMsg, ParameterDirection.Output, 1000, OleDbType.VarChar));
                DbCmd.Parameters.Add(objSybaseDataAccessBase.SetParameter("@op_item_id", ItemId, ParameterDirection.Output, 1000, OleDbType.Numeric));
                DbCmd.ExecuteNonQuery();
ItemId = Convert.ToInt32(DbCmd.Parameters["@op_item_id"].Value);
Posted
Updated 14-Nov-22 5:53am
v2
Comments
Richard MacCutchan 14-Nov-22 12:34pm    
The message probably means that DbCmd.Parameters["@op_item_id"].Value is already an integer.
Graeme_Grant 14-Nov-22 21:56pm    
Please update the question with the complete error message. Usually, the error message contains information to identify exactly why.
[no name] 15-Nov-22 12:50pm    
OleDbType.Numeric is a c# decimal; not int.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900