PDA

View Full Version : خطا هنگام حذف از gridview



fatima2007
سه شنبه 21 شهریور 1391, 22: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();
}



نمی دونم چرا خطا میده!!

aliblue
چهارشنبه 22 شهریور 1391, 09:08 صبح
فکر کنم چون برای نمایش داده ها در گریدویو از SqlDataSource استفاده کردی،برای حذف هم باید با SqlDataSource حذف کنی.برای اینکار کد sql برای حذف رو در قسمت deletecommand از کنترل SqlDataSource بنویس.

moslem.hady
چهارشنبه 22 شهریور 1391, 10:25 صبح
چون commandName اون دکمت delete هست، و delete یک کلمه کلیدیه این خطا رو میده.
یا commandName اون دکمه رو حذف کن، یا کار حذف رو با datasource انجام بده. یعنی براش یه DeleteCommand بنویس. که برطبق کد شما فکر کنم باید commandname رو تغییر بدی

fatima2007
پنج شنبه 23 شهریور 1391, 12:19 عصر
وای مرسی مرسی.مشکلم حل شد.به خاطر اسم دکمه بود.خیلی کارم گیر بود. خدا خیرتون بده:تشویق::تشویق: