Try
ALTER PROCEDURE [dbo].[VerifyLogin]
( @email varchar(50),
@password varchar(20),
@valid BIT OUTPUT
) AS
SET @valid = 0
IF EXISTS(SELECT * FROM customers WHERE email = @email AND password = @password) SET @valid = 1
and
protected void btnLogin_Click(object sender, EventArgs e)
{
try
{
string strConn = Convert.ToString(ConfigurationManager.ConnectionStrings["SQLConnectionString"]);
SqlConnection conn = new SqlConnection(strConn);
conn.Open();
SqlCommand cmd = new SqlCommand("VerifyLogin", conn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("email", txtEmail.Text);
cmd.Parameters.AddWithValue("password", txtPassword.Text);
cmd.Parameters.AddWithValue("valid", false);
cmd.Parameters["@valid"].Direction = ParameterDirection.Output;
cmd.Connection.Open();
cmd.ExecuteNonQuery();
cmd.Connection.Close();
if (cmd.Parameters["@valid"].Value == true)
{
lblLoginError.Visible = true;
lblLoginError.Text = "Login Successful!";
//Response.Redirect("~/default.aspx");
//send to the default page to test
}
else
{
lblLoginError.Visible = true;
lblLoginError.Text = "Login unsuccessful";
//Response.Redirect("Login.aspx");
}
}
catch (Exception ex)
{
Console.Write(ex.ToString());
}
}
In my opinion the result of this sort of single value query should always be returned by an output variable, never a recordset.
Don't forget to click "Mark as Answer" on the post that helped you.
This credits that member, earns you a point and marks your thread as Resolved so we will all know you have been helped.