0

I'm using Oracle database. I have a table called Room and then I made this stored procedure:

 CREATE OR REPLACE PROCEDURE RETRIEVEROOM
 (RoomID IN INTEGER, RID_Out OUT INTEGER) 
 AS
 BEGIN
    Select Room.RoomNumber INTO RID_Out 
    From Room 
    Where Room.RoomNumber = RoomID;
 END;

So I'm trying to send input and output parameters using C# with this code:

private void loadRooms()
{
            OracleCommand cmd = new OracleCommand();
            cmd.Connection = conn;
            cmd.CommandText = "RETRIEVEROOM";
            cmd.CommandType = CommandType.StoredProcedure;

            cmd.Parameters.Add("RoomID", 218);  // Here I send the input parameter
            cmd.Parameters.Add("RID_Out", "").Direction = ParameterDirection.Output; 
            cmd.Parameters["RID_Out"].Size = 255; 
            cmd.ExecuteNonQuery();
            MessageBox.Show(cmd.Parameters["RID_Out"].ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}

When I try to print the value of output parameter in the MessageBox, It prints "RID_Out" not the value of RID_Out which should be 218. How can I solve this problem?

1 Answer 1

1

Guess you want to print Value property of the parameter.

MessageBox.Show((string)cmd.Parameters["RID_Out"].Value, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.