for (int i = 0; i <= GridView1.Rows.Count - 1; i++)
{
string toemail = GridView1.Rows[i].Cells[2].Text;
string FID1 = GridView1.Rows[i].Cells[0].Text;
GridViewRow row = GridView1.Rows[i];
CheckBox Ckbox = (CheckBox)row.FindControl("CheckBoxMark1");
if (Ckbox.Checked == true)
{
sendMail(toemail);
//ClientScript.RegisterStartupScript(Page.GetType(), "validation", "<script language='javascript'>alert('Email send Succesfully')</script>");
ClientScript.RegisterStartupScript(Page.GetType(), "validation", "<script language='javascript'>alert('Email sent Succesfully on " + test + "')</script>");
cn1.Open();
//cmd4.CommandText = "Insert into TrackingFaculty_det (EmailsentDate) values (@EmailsentDate) WHERE FID=@FID";
cmd4.CommandText = "update TrackingFaculty_det SET EmailsentDate=@Email WHERE FID=@FID ";
cmd4.CommandType = CommandType.Text;
cmd4.Connection = cn1;
cmd4.Parameters.Add("@Email", SqlDbType.DateTime, 8);
cmd4.Parameters["@Email"].Value = sdt;
cmd4.Parameters.Add("@FID",SqlDbType.VarChar,10);
cmd4.Parameters["@FID"].Value = FID1;
cmd4.ExecuteNonQuery();
cn1.Close();
}
}
//これはc#
コードの一部であり、asp.net
for loop
が実行されるたびに実行するupdation
必要があるdatabase
場合に問題が発生しますが、クエリをfor loop
複数回実行するとエラーが発生します。これに対する解決策はありますか?update
The variable name '@Email' has already been declared. Variable names must be unique within a query batch or stored procedure.