fatima2007
سه شنبه 21 شهریور 1391, 23:38 عصر
سلام.من یه gridview دارم که از 3 تا جدول ازاطلاعات رو میاره.یه دکمه گداشتم برای حذف دستی که سطری که انتخاب شده. سطر رو حذف می کنه ولی یه خطا می ده :
deleting is not supported by sqldatasource1 unless deletecommand is specified
دستورم اینه
if (e.CommandName == "delete")
{
for (int i = 0; i < GridView1.Rows.Count; i++)
{
CheckBox chk = GridView1.Rows[i].Cells[9].FindControl("CheckBox1") as CheckBox;
//int bookid = Convert.ToInt32(GridView1.SelectedRow.Cells[4].Text);
int bookid = Convert.ToInt32(GridView1.Rows[i].Cells[4].Text);
//int basketid = Convert.ToInt32(GridView1.SelectedRow.Cells[5].Text);
int basketid = Convert.ToInt32(GridView1.Rows[i].Cells[5].Text);
if (chk.Checked)
{
//حذف می کند ولی بعد از حذف خطا می دهد
String str = string.Format("delete from t_relation_book_basket where bookid={0} and basketid={1}", bookid, basketid);
SqlConnection con = new SqlConnection(System.Configuration.ConfigurationMa nager.ConnectionStrings["book-publisherConnectionString"].ConnectionString);
SqlCommand cmd = new SqlCommand(str, con);
con.Open();
cmd.ExecuteNonQuery();
GridView1.DataBind();
con.Close();
}
نمی دونم چرا خطا میده!!
deleting is not supported by sqldatasource1 unless deletecommand is specified
دستورم اینه
if (e.CommandName == "delete")
{
for (int i = 0; i < GridView1.Rows.Count; i++)
{
CheckBox chk = GridView1.Rows[i].Cells[9].FindControl("CheckBox1") as CheckBox;
//int bookid = Convert.ToInt32(GridView1.SelectedRow.Cells[4].Text);
int bookid = Convert.ToInt32(GridView1.Rows[i].Cells[4].Text);
//int basketid = Convert.ToInt32(GridView1.SelectedRow.Cells[5].Text);
int basketid = Convert.ToInt32(GridView1.Rows[i].Cells[5].Text);
if (chk.Checked)
{
//حذف می کند ولی بعد از حذف خطا می دهد
String str = string.Format("delete from t_relation_book_basket where bookid={0} and basketid={1}", bookid, basketid);
SqlConnection con = new SqlConnection(System.Configuration.ConfigurationMa nager.ConnectionStrings["book-publisherConnectionString"].ConnectionString);
SqlCommand cmd = new SqlCommand(str, con);
con.Open();
cmd.ExecuteNonQuery();
GridView1.DataBind();
con.Close();
}
نمی دونم چرا خطا میده!!