public partial class D2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{ }
protected void lbtDel_Command(object sender, CommandEventArgs e)
{
if (Session["admin"] != null)
{
//string userID = Request.QueryString["userID"].ToString();
string userID = e.CommandArgument.ToString();
SqlConnection conn = DB.createCon();
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "delete from guest where ID='" + userID + "'";
cmd.Connection = conn;
if (Convert.ToInt32(cmd.ExecuteNonQuery())> 0)
{
Response.Write("<script>alert('删除成功!');location.href='D2.aspx';</script>");
}
else
{
Response.Write("<script>alert('删除失败!');location.href='D2.aspx';</script>");
}
}
else
{
Response.Write("<script>alert('对不起,只有管理员有权利删除留言,如果你是管理员,请先登录!');location.href='D1.aspx';</script>");
}
}
protected void lbtReply_Command(object sender, CommandEventArgs e)
{
if (Session["admin"] != null)
{
//string userID = Request.QueryString["userID"].ToString();
string userID = e.CommandArgument.ToString();
Response.Redirect("D5.aspx?userID=" + userID + "");
}
else
{
Response.Write("<script>alert('对不起,只有管理员有权利回复,如果你是管理员,请先登录!');location.href='D1.aspx';</script>");
}
}
}
这是怎么回事,老是显示删除失败
{
protected void Page_Load(object sender, EventArgs e)
{ }
protected void lbtDel_Command(object sender, CommandEventArgs e)
{
if (Session["admin"] != null)
{
//string userID = Request.QueryString["userID"].ToString();
string userID = e.CommandArgument.ToString();
SqlConnection conn = DB.createCon();
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "delete from guest where ID='" + userID + "'";
cmd.Connection = conn;
if (Convert.ToInt32(cmd.ExecuteNonQuery())> 0)
{
Response.Write("<script>alert('删除成功!');location.href='D2.aspx';</script>");
}
else
{
Response.Write("<script>alert('删除失败!');location.href='D2.aspx';</script>");
}
}
else
{
Response.Write("<script>alert('对不起,只有管理员有权利删除留言,如果你是管理员,请先登录!');location.href='D1.aspx';</script>");
}
}
protected void lbtReply_Command(object sender, CommandEventArgs e)
{
if (Session["admin"] != null)
{
//string userID = Request.QueryString["userID"].ToString();
string userID = e.CommandArgument.ToString();
Response.Redirect("D5.aspx?userID=" + userID + "");
}
else
{
Response.Write("<script>alert('对不起,只有管理员有权利回复,如果你是管理员,请先登录!');location.href='D1.aspx';</script>");
}
}
}
这是怎么回事,老是显示删除失败
解决方案 »
- 关于ASP.Net制定的错误页面
- 同样的.net程序在 windows 2003 iis上传速度慢
- 一个js的mouseover问题。是关于鼠标移上去显示div,然后切换屏幕,回来后不显示div
- sql 时间戳问题...
- Server.Transfer方法在页面间传值
- 在.net中如何向Oracle中传参(不用存储过程)
- 高分求无限级分类(C#+ASP.NET),简单示例及注释(在线等待结贴,谢谢)
- 未将对象引用设置到对象的实例?
- 超时后重定向的问题!!
- 急!简单问题!ASP.NET做的网页不能浏览,请高手指点!!
- Gridview分页模板列状态如何存储(在线)
- 关于JS加入收藏夹得问题 大家帮帮忙啊 急
然后检查数据库中的“ID”字段是否是字符型
另外Convert.ToInt32(cmd.ExecuteNonQuery())这句话我没太看懂,这样的转换有什么意义么?
userID没取到值,Convert.ToInt32(cmd.ExecuteNonQuery())是返回执行SQL语句后影响的行数,Convert.ToInt32也可以不要的
{
conn.open();
SqlCommand cmd = new SqlCommand("delete from guest where ID='" + userID + "'",conn);
int i=Convert.ToInt32(cmd.ExecuteNonQuery());
}
断点设在这,调试看看值
cmd.CommandType = CommandType.Text;
<linkbutton id="lbtDel" runat="server" commandargument="<%#Eval("UserID")>"
if(userID==null){
Response.Write(获取id值失败);
}else{ SqlConnection conn = DB.createCon();
..........
}