public void ProcessRequest (HttpContext context) {
context.Response.ContentType = "text/html";
int qid = Convert.ToInt32(context.Request["id"]);
string str = ConfigurationManager.ConnectionStrings["connStr"].ConnectionString;
string sql = "delete t_users where id=@id";
using(SqlConnection conn=new SqlConnection (str))
using (SqlCommand cmd = new SqlCommand(sql, conn))
{
cmd.Parameters.Add(new SqlParameter("@id", qid));
conn.Open();
cmd.ExecuteNonQuery();
}
context.Response.Redirect("/index.ashx");
context.Response.ContentType = "text/html";
int qid = Convert.ToInt32(context.Request["id"]);
string str = ConfigurationManager.ConnectionStrings["connStr"].ConnectionString;
string sql = "delete t_users where id=@id";
using(SqlConnection conn=new SqlConnection (str))
using (SqlCommand cmd = new SqlCommand(sql, conn))
{
cmd.Parameters.Add(new SqlParameter("@id", qid));
conn.Open();
cmd.ExecuteNonQuery();
}
context.Response.Redirect("/index.ashx");
}

点击确定删除数据

删除完成。
本文介绍了一个使用ASP.NET实现的简单删除操作。该操作通过获取HTTP请求中的'id'参数来定位要删除的数据,并利用ADO.NET连接数据库执行删除SQL语句。具体步骤包括:设置响应类型为HTML,获取URL参数,配置数据库连接字符串,构造SQL删除语句,添加参数并执行删除操作。

被折叠的 条评论
为什么被折叠?



