I am trying to check if a user is in my database, my return value from my function is either a 't' or an 'f'. as below:
CREATE OR REPLACE FUNCTION LOGIN
(p_Naam in varchar2
,p_Wachtwoord in varchar2)
return varchar2
is
v_count number;
BEGIN
select count(*) into v_count
from Lid
where Naam = p_Naam
and Wachtwoord = p_Wachtwoord;
if v_count > 0 then
return 't';
end if;
return 'f';
END LOGIN;
now i call this function with my C# code as below:
public bool LogIn(string gebruikersnaam, string wachtwoord)
{
string s;
var cmd = new OracleCommand
{
Connection = conn,
CommandText = "Login",
CommandType = CommandType.StoredProcedure
};
cmd.Parameters.Add("p_Naam", OracleDbType.Varchar2).Value = gebruikersnaam;
cmd.Parameters.Add("p_Wachtwoord", OracleDbType.Varchar2).Value = wachtwoord;
cmd.Parameters.Add("return_value", OracleDbType.Varchar2, ParameterDirection.ReturnValue);
try
{
conn.Open();
cmd.ExecuteNonQuery();
s = cmd.Parameters["return_value"].Value.ToString();
}
finally
{
conn.Close();
}
return s == "t";
}
when i try this funcion within my oracle developer i get an output. only in my C# code, s always comes out as ""
in my sql developer the following gives me 't'
BEGIN
dbms_output.put_line(LOGIN('Willem Koonings', 'willem'));
END;
cmd.Parameters.Add("return_value", OracleType.VarChar2, 1).Direction = ParameterDirection.ReturnValue;. The third parameter toAdd, in this case, is supposed to be the size of the column - in this case you're only returning a single character so it should be 1. ParameterDirection is a property of the parameter. Share and enjoy.