I have a procedure that returns value, but when it arrives in the ExecuteScalar () of c # it returns me the error "Object reference not set to an instance of an object"
The procedure is correct
private string IdentificaPat()
{
db.Configuration.AutoDetectChangesEnabled = false;
db.Configuration.ValidateOnSaveEnabled = false;
string retorno;
string constr = ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString;
using (SqlConnection con = new SqlConnection(constr))
{
using (SqlCommand cmd = new SqlCommand("Sp_InsertContratoGestores"))
{
cmd.CommandTimeout = 300;
cmd.CommandType = CommandType.StoredProcedure;
cmd.Connection = con;
con.Open();
retorno = cmd.ExecuteScalar().ToString();
con.Close();
}
}
if(retorno == "vazio")
{
return "Vazio";
}
else
{
return "Sem novos contratos";
}
db.Configuration.AutoDetectChangesEnabled = true;
db.Configuration.ValidateOnSaveEnabled = true;
}