if you could please help me out… i am try to create o forgot password method.access my database and send an e-mail. if you please help me out since i don’t have a lot of experience. thanking you in advance. Login is unique. C#
protected void LinkButton1_Click(object sender, EventArgs e)
{
var sqlCon = new SqlConnection(System.Configuration.ConfigurationManager.
ConnectionStrings["ConnectionString"].ConnectionString);
SqlCommand cmd = new SqlCommand();
cmd.Connection = sqlCon;
cmd.CommandText = "select Password from Person where Login= @Login ";
cmd.Connection.Open();
string Password = cmd.ExecuteScalar().ToString();
cmd.Connection.Close();
cmd.Dispose();
SqlCommand cmd1 = new SqlCommand();
cmd1.Connection = sqlCon;
cmd1.CommandText = "select e_mail from Person where Login= @Login ";
cmd1.Connection.Open();
string e_mail = cmd.ExecuteScalar().ToString();
cmd.Connection.Close();
cmd.Dispose();
if (Login.Text.Equals("@Login"))
{
Class1 S = new Class1();
S.sendMail(e_mail, "Your Password request", Password);
Response.Write("<script>");
}
}
first you can make one call to sql instead of two,
try somthing like this (not tested!)