i created a stored proc to return a bool and i am trying to build its connection in my app (asp.net mvc c#) but i am not sure how i should execute the command to properly return the bool.
code:
public virtual bool CheckEmail(string email, int Id)
{
SqlCommand _command = new SqlCommand("dbo.CheckEmail");
_command.Connection = DbInstance.SqlConnection;
_command.CommandType = CommandType.StoredProcedure;
_command.Parameters.Add(new SqlParameter { ParameterName = "Email", SqlDbType = SqlDbType.NVarChar, Value = email });
_command.Parameters.Add(new SqlParameter { ParameterName = "Id", SqlDbType = SqlDbType.Int, Value = Id});
........
}
I thought i would try:
var _result = DbInstance.ExecuteAsSingle<int>(_command, r => r.GetValueOrDefault<int>(0));
if (_result > 0)
return true;
return false;
the error i would get is: {"Specified cast is not valid."}
any helpful tips would be great - thanks.