Saman Ice
یک شنبه 07 خرداد 1391, 17:34 عصر
سلام
من این کد رو نوشتم برای حذف رکوردهای که تو گرید انتخاب شدن، ولی حذف نمیکنه و هیچ خطایی هم نمیده
string strID = string.Empty;
for (int i = 0; i < GridView1.Rows.Count; i++)
{
CheckBox chkDelete = (CheckBox)GridView1.Rows[i].Cells[0].FindControl("CheckBox1");
if (chkDelete != null)
{
if (chkDelete.Checked)
{
strID = (GridView1.Rows[i].Cells[5].Text).ToString();
SqlConnection conn = new SqlConnection("Data Source=saman-pc;Initial Catalog=University;Integrated Security=True");
conn.Open();
SqlCommand cmd = new SqlCommand();
cmd.Connection = conn;
string qeury = "DELETE FROM selectunits WHERE studentid='" + int.Parse(idnum.Text) + "' and lessonid='" + int.Parse(strID) + "'";
cmd.CommandText = qeury;
cmd.ExecuteNonQuery();
conn.Close();
}
}
}
GridView1.DataBind();
}
من این کد رو نوشتم برای حذف رکوردهای که تو گرید انتخاب شدن، ولی حذف نمیکنه و هیچ خطایی هم نمیده
string strID = string.Empty;
for (int i = 0; i < GridView1.Rows.Count; i++)
{
CheckBox chkDelete = (CheckBox)GridView1.Rows[i].Cells[0].FindControl("CheckBox1");
if (chkDelete != null)
{
if (chkDelete.Checked)
{
strID = (GridView1.Rows[i].Cells[5].Text).ToString();
SqlConnection conn = new SqlConnection("Data Source=saman-pc;Initial Catalog=University;Integrated Security=True");
conn.Open();
SqlCommand cmd = new SqlCommand();
cmd.Connection = conn;
string qeury = "DELETE FROM selectunits WHERE studentid='" + int.Parse(idnum.Text) + "' and lessonid='" + int.Parse(strID) + "'";
cmd.CommandText = qeury;
cmd.ExecuteNonQuery();
conn.Close();
}
}
}
GridView1.DataBind();
}