c# - Oracle Stored Procedure not returning any value -
i'm calling oracle stored procedure c# login form it's not returning value. dt.rows.count
below 0 , if part of if-else statement never executed, gets else part.
c# code:
string sconnectionstring = "data source=xe;user id=system;password=system;"; oracleconnection myconnection = new oracleconnection(sconnectionstring); myconnection.open(); oraclecommand mycommand = new oraclecommand("spvalidatedba", myconnection); mycommand.commandtype = commandtype.storedprocedure; mycommand.commandtext = "spvalidatedba"; mycommand.parameters.add("username", oracledbtype.varchar2, 50); mycommand.parameters["username"].value = txtusrid.text.tostring(); mycommand.parameters.add("userpassword", oracledbtype.varchar2, 50); mycommand.parameters["userpassword"].value = txtpassword.text.tostring(); mycommand.parameters.add("datacount", oracledbtype.int32, 20).direction = parameterdirection.output; oracledatareader myreader = mycommand.executereader(); datatable dt = new datatable(); dt.load(myreader); if (dt.rows.count>0) { custommsgbox.show("\tlogin successful\t" + environment.newline + "welcome db utilities tool", "db utilities tool", "ok", "cancel"); dba dba = new dba(); dba.show(); this.hide(); } else custommsgbox.show("please enter correct username/password", "db utilities tool", "ok", "cancel"); myconnection.close(); }
oracle stored procedure:
create or replace procedure spvalidatedba( username in varchar2, userpassword in varchar2, datacount out integer) begin select count(*) datacount dba_user user_name=username , user_pwd=userpassword , user_role = 'dba'; end spvalidatedba;
please note table dba_user contains 1 row values as:
user_name user_pwd user_role dask password dba
thus, datacount
in above stored procedure should return 1 row value 1 when inputs login form dask(username) & password(userpassword), it's not returning anything.
can please tell me i'm going wrong this? need issue resolved soon.
you not returning result set sp datatable empty. returning value in output parameter. use executenonquery
, read value parameter.
try this
mycommand.executenonquery(); int datacount = 0; if(mycommand.parameters["datacount"] ! =null) { datacount = convert.toint32(mycommand.parameters["datacount"].value); } if(datacount > 0) { custommsgbox.show("..."); }
Comments
Post a Comment