I am getting an error "Must declare scalar variable @id" but I can't find where I am wrong.
Thanks
protected void Page_Load(object sender, EventArgs e)
{
string constr = ConfigurationManager.ConnectionStrings["Q_SS_regnConnectionString1"].ConnectionString;
SqlConnection con = new SqlConnection(constr);
SqlCommand cmd2 = new SqlCommand("select * from JS_Resume where CompanyEmail='" + Session["mail"].ToString() + "' and Status='UnApproved'", con);
SqlDataAdapter da = new SqlDataAdapter(cmd2);
DataTable dt = new DataTable();
da.Fill(dt);
GridView2.DataSource = dt;
GridView2.DataBind();
if (Request.QueryString["Id"] != null)
{
var Id = Request.QueryString["Id"];
var email = Request.QueryString["email"];
//var Password = Request.QueryString["Password"];
try
{
SqlCommand cmd = new SqlCommand("update JS_Resume set status='Approved' where Id=@id", mycon);
cmd.Parameters.AddWithValue("@id", Id);
//Response.Write(U_id);
mycon.Open();
cmd.ExecuteNonQuery();
cmd.Parameters.Clear();
cmd.ExecuteNonQuery();
ClientScript.RegisterStartupScript(GetType(), "alert", "alert('Approved.');", true);
}
catch (Exception ex)
{
Response.Write(ex);
ClientScript.RegisterStartupScript(GetType(), "alert", "alert('Not Approved.');", true);
}
finally
{
mycon.Close();
}
try
{
SqlCommand cmd = new SqlCommand("select * from JS_Resume where Id=@id and CompanyEmail='" + Session["mail"].ToString() + "'", mycon);
cmd.Parameters.AddWithValue("@id", Id);
cmd.CommandType = System.Data.CommandType.Text;
cmd.Connection = mycon;
mycon.Open();
SqlDataReader dar = cmd.ExecuteReader();
if (dar.Read())
{
Id = dar["Id"].ToString();
email = dar["email"].ToString();
//Password = dar["Password"].ToString();
using (MailMessage mm = new MailMessage("jobopediaHere@gmail.com", email))
{
mm.Subject = "Resume Approved";
mm.Body = "Congratulations..!!\nYour Resume has been Approved.\nYour Username: " + email + "\n For Further Process Company Will Contact You By Your Registered Email or Phone.\nThank you For Connecting With Us.";
mm.IsBodyHtml = false;
SmtpClient smtp = new SmtpClient();
smtp.Host = "smtp.gmail.com";
smtp.EnableSsl = true;
NetworkCredential NetworkCred = new NetworkCredential("xyz@gmail.com", "123");
smtp.UseDefaultCredentials = true;
smtp.Credentials = NetworkCred;
smtp.Port = 587;
smtp.Send(mm);
ClientScript.RegisterStartupScript(GetType(), "alert", "alert(' Email Sent.');", true);
}
}
}
catch (Exception)
{
//Response.Write(ex.ToString());
}
finally
{
//Label1.Text = ("message sent");
}
}
}