We help IT Professionals succeed at work.
Get Started

Lookup user against two values

asp_net2
asp_net2 asked
on
490 Views
Last Modified: 2012-08-13
Hello Experts,

I have the following code below. I need to compare two values in my database against the values entered in two TextBox controls and if they exist send an email to the email address listed in DB and if they don't exist display error message. Please see my attached code and stored procedure.


protected void btn_ForgotPassword_Click(object sender, EventArgs e)
    {
        using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["HealthCourses"].ConnectionString))
        {
            SqlCommand cmd = new SqlCommand();
            cmd.CommandText = "HealthCourses_VerifyUsernameEmail";
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Connection = conn;

            cmd.Parameters.Add("@users_username", SqlDbType.VarChar, 50).Value = txtUsername.Text;
            cmd.Parameters.Add("@users_email", SqlDbType.VarChar, 100).Value = txtEmail.Text;

            try
            {
                conn.Open();

                SqlDataReader rdr = cmd.ExecuteReader();

                if (rdr.Read())
                {
                    Session["UsersID"] = rdr["users_id"].ToString();
                    SendForgotPasswordEmail();
                }
                else
                {
                    lblForgotPasswordError.Text = "Invalid Credentials";
                }

                Response.Redirect("forgotpassword_success.aspx");
            }

            catch (Exception ex)
            {
                lblForgotPasswordError.Text = ex.Message.ToString();
            }
        }
    }

Open in new window

CREATE PROCEDURE HealthCourses_VerifyUsernameEmail

(
@users_username varchar(50),
@users_email varchar(100)
)

AS 

SELECT users_id, users_username, users_email
FROM dbo.HealthCourses_Users
WHERE users_username = @users_username AND users_email = @users_email

Open in new window

Comment
Watch Question
Full Stack .NET Developer
Commented:
This problem has been solved!
Unlock 2 Answers and 25 Comments.
See Answers
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE