I have a function in Oracle that returns a sequence number. When I try to get that value in C# by a parameter it always tells me that the parameter type is invalid. A sample value of that returned value is 115545. If indeed this error is correct then what is the correspondent in ODBCType for this value? If it isn’t correct then what is the problem?
Oracle function is:
FUNCTION Get_Next_Message_Id__
RETURN NUMBER IS
temp_ NUMBER;
CURSOR get_in_message_id_seq IS
SELECT in_message_id_seq.NEXTVAL
FROM dual;
BEGIN
General_SYS.Init_Method(lu_name_, 'IN_MESSAGE_API', 'Get_Next_Message_Id__', TRUE);
OPEN get_in_message_id_seq;
FETCH get_in_message_id_seq INTO temp_;
CLOSE get_in_message_id_seq;
RETURN(temp_);
END Get_Next_Message_Id__;
C# Code:
OdbcConnection myConnection = new OdbcConnection(ODBC_CLass.ifsconnectionstring);
OdbcParameter next_id = new OdbcParameter();
next_id.Direction = ParameterDirection.Output;
myConnection.Open();
OdbcCommand command = new OdbcCommand("{? = call ifsapp.in_message_api.Get_Next_Message_Id__}", myConnection);
command.CommandType = CommandType.StoredProcedure;
next_id = command.Parameters.Add("temp_", OdbcType.Int);
int k = command.ExecuteNonQuery();
MessageBox.Show("next_id: " + next_id.Value);
I believe the problem is in the way you’re setting
next_id. You’re first creating anOdbcParameterand setting its direction – but then completely ignoring it, and reassigning the variable using theAddmethod, which will be creating an “in” parameter by default. Try this instead:Note that you should also be using
usingstatements for the connection and command, to ensure they’re cleaned up at the end of the code, whatever happens.