I have a small login with two text fields (email and document number), which when I hit the "enter" button I want to be validated in my stored procedure, but it shows me an exception error:
System.NullReferenceException: Referencia a objeto no establecida como instancia de un objeto, error en la linea 31.
Línea 29: com.Parameters.Add("id_usu_numerodocumento", Convert.ToInt32(numeroDocumento.Text.Trim()));
Línea 30: com.Connection = conexion;
Línea 31: int result = (Int32)com.ExecuteScalar();
Línea 32:
Línea 33: if (result == 1)
My c# code is as follows:
string con = ConfigurationManager.ConnectionStrings["connectOrcl"].ConnectionString;
//conexión a la base de datos
OracleConnection conexion = new OracleConnection(con);
conexion.Open();
OracleCommand com = new OracleCommand("INGRESO_USUARIO", conexion);
com.CommandType = System.Data.CommandType.StoredProcedure;
com.Parameters.Add("usu_email", correoElectronico.Text.Trim());
com.Parameters.Add("id_usu_numerodocumento", Convert.ToInt32(numeroDocumento.Text.Trim()));
com.Connection = conexion;
int result = (Int32)com.ExecuteScalar();
if (result == 1)
{
Response.Redirect("admin/dashboard.aspx");
}
if (result == 0)
{
Response.Redirect("ingreso.aspx");
}
conexion.Close();
And my procedure:
CREATE OR REPLACE PROCEDURE INGRESO_USUARIO
(
usu_email varchar,
id_usu_numerodocumento int
)
AS
usuNumeroDoc INT;
BEGIN
SELECT COUNT(*) INTO usuNumeroDoc FROM LA_USUARIO WHERE usu_email = usu_email AND id_usu_numerodocumento = id_usu_numerodocumento;
END;
If the COUT is equal to 1, it passes, if it is equal to 0, it does not pass.
Thanks for your help!
You can read this tutorial.
https://www.c-sharpcorner.com/article/calling-oracle-stored-procedures-from-microsoft-net/
You have to define at least one parameter as OUT in your stored procedure or you can create a function.
Greetings.
I managed to do it by sending an OUT parameter of type RefCursor in the Oracle procedure:
And in C# I took the value of that position and stored it in a variable to compare it: