C# Getting Varchar2 (String out of Stored Procedure)
767018May 10 2010 — edited May 10 2010Hey,
This is totally puzzling me. I have the following c# code that should return a string in output with wheter the user is an admin or not. I keep getting wrong number of arguements errors and object not an instance error. Please take a look and see if there is anything you notice I am doing wrong. It is well documented about returning cursors, but searching for returning individual fields has yet to leave me with an example that works for me.
Thank you so much!!!
Jeffrey Kevin Pry
C# Code_
public static String checkGroup(String userName)
{
OracleConnection db = new OracleConnection();
OracleCommand mycom = new OracleCommand();
mycom.CommandText = "pg.is_user_admin";
mycom.Connection = db;
mycom.CommandType = CommandType.StoredProcedure;
mycom.Parameters.Add("USER_ID", OracleType.VarChar, 2000).Value = userName;
mycom.Parameters["USER_ID"].Direction = ParameterDirection.Input;
mycom.Parameters.Add("IS_ADMIN", OracleType.VarChar, 2000).Direction = ParameterDirection.Output;
String output = mycom.Parameters["IS_ADMIN"].Value.ToString();
mycom.ExecuteNonQuery();
return output;
}
Package Header_
create or replace
PACKAGE pg AS
PROCEDURE is_user_admin (USER_ID IN VARCHAR2, IS_ADMIN IN OUT VARCHAR2);
end pg;
Package Body_
create or replace
PACKAGE BODY pg AS
PROCEDURE is_user_admin (USER_ID IN VARCHAR2, IS_ADMIN IN OUT VARCHAR2) IS
BEGIN
SELECT h.IS_ADMIN into IS_ADMIN from param_g_users h where username = USER_ID;
EXCEPTION
WHEN NO_DATA_FOUND THEN
IS_ADMIN := '0';
END;
END pg;
Edited by: jeffrey.pry on May 10, 2010 6:19 AM
Edited by: jeffrey.pry on May 10, 2010 6:20 AM