2016-02-12 209 views
0

我有一个复选框的中继器,我想删除子表中的项目/记录从复选框中选中的项目/记录。有任何想法吗?删除复选框中的复选框

表结构:
软件 CategoryID=100, SubCategoryID=NULL (main category) ASP.NET CategoryID=100, SubCategoryID=100 (sub category)

我得到错误:

Incorrect syntax near '='. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.Data.SqlClient.SqlException: Incorrect syntax near '='.

// select all 
protected void btnSelectAll_Click(object sender, EventArgs e) 
    { 
     foreach (RepeaterItem ri in rpCategory.Items) 
     { 
CheckBox checkBoxApproved = ri.FindControl("checkBoxApproved") as CheckBox; 
      if (checkBoxApproved != null) 
      { 
       if (checkBoxApproved.Checked == true) 
       { 
        checkBoxApproved.Checked = false; 
       } 
       else 
       { 
        checkBoxApproved.Checked = true; 
       } 
      } 
     } 
    } 

    // delete all 
    protected void btnDelete_Click(object sender, EventArgs e) 
     { 
      for (int i = 0; i < rpCategory.Items.Count; i++) 
      { 
       CheckBox CheckBox1 = (CheckBox) 
       rpCategory.Items[i].FindControl("checkBoxApproved"); 

       if (((CheckBox)rpCategory.Items[i].FindControl("checkBoxApproved")).Checked) 
       { 
        CheckBox CheckBox = (CheckBox)rpCategory.Items[i].FindControl("checkBoxApproved"); 

        SqlConnection cnn = system.baglan(); 
        SqlCommand cmd = new SqlCommand("DELETE FROM TBLCATEGORIES where SubCategoryID="+CategoryID, cnn); 
        cmd.ExecuteNonQuery(); 
        Response.Redirect("SubCategories.aspx?Message=Success!"); 
       } 
      } 
+0

阿霉素空间后SubCategoryID后,检查值,您需要更改'SubCategoryID = + “CategoryID'到'SubCategoryID =” + CategoryID'! '+'在'''错误的一边,我想知道这是为什么这个编译... –

+0

SqlCommand cmd = new SqlCommand("DELETE FROM TBLCATEGORIES where 'SubCategoryID=+"CategoryID, cnn);' 

将其更改为

SqlCommand cmd = new SqlCommand("DELETE FROM TBLCATEGORIES where SubCategoryID=" +CategoryID, cnn); 

回答

1

你的下面一行中有

错误类别ID
+0

CategoryID的值是什么,它的值来自你的btnSecilenleriSil_Click方法的哪个位置? –

+0

SeçilenleriSil Shqiptar

+0

CategoryID的值是什么? –