。net datalist控件 添加按钮 删除此条几率问题 !
<asp:LinkButtonID="Link1"runat="server"CommandName="delete"Font-Underline="False">删除<...
<asp:LinkButton ID="Link1" runat="server" CommandName="delete"
Font-Underline="False" >删除</asp:LinkButton>
protected void DataList1_DeleteCommand(object source, DataListCommandEventArgs e)
{
if (e.CommandName == "delete")
{
string strid = this.DataList1.DataKeys[e.Item.ItemIndex].ToString(); //获取当前DataList控件列
OleDbConnection con = DB.createDB();
OleDbCommand cmd = new OleDbCommand();
cmd.Connection = con;
con.Open();
string strSql = "Delete from tb_liuyan where ID='" + Convert.ToInt32(strid) + "'";
cmd.ExecuteNonQuery();
Response.Write("<script language=javascript>alert('恭喜您,信息删除成功!!');location.href('liuyanguanli.aspx')</script>");
con.Close();
}
}
各位帮我看看那写错啦 详细指点下 我毕业设计忙这用 谢谢啦 展开
Font-Underline="False" >删除</asp:LinkButton>
protected void DataList1_DeleteCommand(object source, DataListCommandEventArgs e)
{
if (e.CommandName == "delete")
{
string strid = this.DataList1.DataKeys[e.Item.ItemIndex].ToString(); //获取当前DataList控件列
OleDbConnection con = DB.createDB();
OleDbCommand cmd = new OleDbCommand();
cmd.Connection = con;
con.Open();
string strSql = "Delete from tb_liuyan where ID='" + Convert.ToInt32(strid) + "'";
cmd.ExecuteNonQuery();
Response.Write("<script language=javascript>alert('恭喜您,信息删除成功!!');location.href('liuyanguanli.aspx')</script>");
con.Close();
}
}
各位帮我看看那写错啦 详细指点下 我毕业设计忙这用 谢谢啦 展开
1个回答
展开全部
你的 sql语句没有执行,
cmd.CommandText=strSql;
cmd.ExecuteNonQuery();
此外还要注意下你的sql 如果ID字段是数值类型
string strSql = "Delete from tb_liuyan where ID=" + Convert.ToInt32(strid);
不应该再加单引号
cmd.CommandText=strSql;
cmd.ExecuteNonQuery();
此外还要注意下你的sql 如果ID字段是数值类型
string strSql = "Delete from tb_liuyan where ID=" + Convert.ToInt32(strid);
不应该再加单引号
更多追问追答
追问
string strSql = "Delete from tb_liuyan where ID=" + Convert.ToInt32(strid) + "";
cmd.CommandText = strSql;
cmd.ExecuteNonQuery();
Response.Write("alert('恭喜您,信息删除成功!!');location.href('liuyanguanli.aspx')");
con.Close(); 还是失败啦 麻烦帮我看下
追答
string strSql = "Delete from tb_liuyan where ID=" + Convert.ToInt32(strid);
仔细看,把你的改成我写的那个
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询