I have the following method:
public bool CheckEmail(string email)
{
bool success = false;
string name;
using (SqlConnection con = new SqlConnection(Internal_Audit_Capture.Properties.Settings.Default.Intenal_AuditDB))
{
con.Open();
try
{
using (SqlCommand command = new SqlCommand("IntAudit.p_checkEmail", con))
{
command.CommandType = CommandType.StoredProcedure;
command.Parameters.Add(new SqlParameter("@email", maskedTextBox1.Text.Trim()));
command.Parameters.Add("@success", SqlDbType.Bit).Direction = ParameterDirection.Output;
command.Parameters.Add("@name", SqlDbType.VarChar).Direction = ParameterDirection.Output;
command.ExecuteNonQuery();
success = (bool)command.Parameters["@success"].Value;
name = (string)(command.Parameters["@name"].Value);
}
return success;
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
return success;
}
}
}p_CheckEmail queries the table:
[IntAudit].[LOGINDETAILS]( [ID] [int] IDENTITY(1,1) NOT NULL, [NAME] [varchar](30) NOT NULL, [PASSWORD] [nvarchar](30) NOT NULL, [ADMIN] [bit] NULL, [EMAIL] [varchar](50) NOT NULL, PRIMARY KEY CLUSTERED ( [ID] ASC )
And the procedure is:
create procedure IntAudit.p_checkEmail @email varchar(50), @success bit OUTPUT, @name varchar(30) OUTPUT as set nocount on; if(exists(select 1 from [IntAudit].[LOGINDETAILS] where [EMAIL] = @email)) begin select @name = [NAME] from [IntAudit].[LOGINDETAILS] where [EMAIL] = @email set @success = 1 return end else begin set @name = null set @success = 0 return end go
Now it runs fine in SSMS but I get the following error in debug from the application:
Any advice or clue will be highly appreciated.