这个是一个删除按钮事件,Repeater+CheckBox实现新闻系统里的新闻批量删除.
语法用的是delete from XX where id in ();
执行无错误 但是记录没删掉.
protected void bt_del_Click(object sender, EventArgs e)
{
string sID="";
string strConn = "Provider=Microsoft.Jet.OleDb.4.0;data source=" + Server.MapPath("db.mdb");
OleDbConnection objConn = new OleDbConnection(strConn);
foreach (RepeaterItem item in rptList.Items)
{
CheckBox chkbox1 = (CheckBox)item.FindControl("ckBox_single");
if (chkbox1.Checked == true)
{
sID += ((HtmlInputHidden)item.FindControl("SelectedID")).Value + ',';
}
}
string strSql = "delete from guestbook where g_id in (@id)";
OleDbCommand cmd = new OleDbCommand(strSql, objConn);
cmd.Parameters.AddWithValue("@id", sID);
objConn.Open();
cmd.ExecuteNonQuery();
objConn.Close();
}
比如断点调试,sID中的值是(17,18,) 不成功.但是如果直接把(@id)换成(17,18,)就是成功的....
不明白的说
语法用的是delete from XX where id in ();
执行无错误 但是记录没删掉.
protected void bt_del_Click(object sender, EventArgs e)
{
string sID="";
string strConn = "Provider=Microsoft.Jet.OleDb.4.0;data source=" + Server.MapPath("db.mdb");
OleDbConnection objConn = new OleDbConnection(strConn);
foreach (RepeaterItem item in rptList.Items)
{
CheckBox chkbox1 = (CheckBox)item.FindControl("ckBox_single");
if (chkbox1.Checked == true)
{
sID += ((HtmlInputHidden)item.FindControl("SelectedID")).Value + ',';
}
}
string strSql = "delete from guestbook where g_id in (@id)";
OleDbCommand cmd = new OleDbCommand(strSql, objConn);
cmd.Parameters.AddWithValue("@id", sID);
objConn.Open();
cmd.ExecuteNonQuery();
objConn.Close();
}
比如断点调试,sID中的值是(17,18,) 不成功.但是如果直接把(@id)换成(17,18,)就是成功的....
不明白的说