我有一个带有复选框的转发器,我想从表中删除子类别中的项目/记录,并选中复选框。任何想法?
表格结构:
软件
CategoryID=100, SubCategoryID=NULL (main category)
ASP.NET
CategoryID=100, SubCategoryID=100 (sub category)
我收到了错误:
'='附近的语法不正确。 描述:执行当前Web请求期间发生未处理的异常。请查看堆栈跟踪以获取有关错误及其源自代码的位置的更多信息。 异常详细信息:System.Data.SqlClient.SqlException:'='附近的语法不正确。
// 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 :(得分:1)
您的以下行中有错误
SqlCommand cmd = new SqlCommand("DELETE FROM TBLCATEGORIES where `SubCategoryID=+"CategoryID, cnn);`
将其更改为
SqlCommand cmd = new SqlCommand("DELETE FROM TBLCATEGORIES where SubCategoryID=" +CategoryID, cnn);