📄 comment.aspx.cs
字号:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Configuration;
using System.Data.OleDb;
namespace MyBlog
{
/// <summary>
/// comment 的摘要说明。
/// </summary>
public partial class comment : System.Web.UI.Page
{
protected void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
if(!IsPostBack)
{
if((bool)Session["pwd"] == false)
Response.Redirect("codeReq.aspx");
String strValue = "select * from commentInfo where contextID = '"+Request["contextID"]+"'";
String strConn = ConfigurationSettings.AppSettings["webblog"] + Server.MapPath("WebBlog.mdb");
OleDbConnection cn = new OleDbConnection();
cn.ConnectionString = strConn;
OleDbDataAdapter myCommand = new OleDbDataAdapter(strValue, cn);
DataSet ds = new DataSet();
myCommand.Fill(ds, "commentInfo");
commentDataGrid.DataSource = ds.Tables["commentInfo"].DefaultView;
commentDataGrid.DataBind();
}
}
#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.commentDataGrid.DeleteCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.commentDataGrid_DeleteCommand);
}
#endregion
private void commentDataGrid_DeleteCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
try
{
String deleteCmd = "delete from commentInfo where commentID = @commentID";
String strConn = ConfigurationSettings.AppSettings["webblog"] + Server.MapPath("WebBlog.mdb");
OleDbConnection cn = new OleDbConnection();
cn.ConnectionString = strConn;
OleDbCommand myCommand = new OleDbCommand(deleteCmd, cn);
myCommand.Parameters.Add(new OleDbParameter("@commentID", OleDbType.VarChar, 38));
myCommand.Parameters["@commentID"].Value =commentDataGrid.DataKeys[e.Item.ItemIndex].ToString();
cn.Open();
myCommand.Parameters.Clear();
myCommand.CommandText = "update contextInfo set viewCount = viewCount - 1 where contextID = '{"+Request["contextID"]+"}'";
myCommand.ExecuteNonQuery();
try
{
myCommand.ExecuteNonQuery();
Message.Text = "删除成功";
}
catch(System.Data.OleDb.OleDbException)
{
Message.Text ="出错了";
}
cn.Close();
}
catch(System.Data.OleDb.OleDbException)
{
Message.Text ="出错了";
}
String strValue1 = "select * from commentInfo where contextID = '"+Request["contextID"]+"'";
String strConn1 = ConfigurationSettings.AppSettings["webblog"] + Server.MapPath("WebBlog.mdb");
OleDbConnection cn1 = new OleDbConnection();
cn1.ConnectionString = strConn1;
OleDbDataAdapter myCommand1 = new OleDbDataAdapter(strValue1, cn1);
DataSet ds = new DataSet();
myCommand1.Fill(ds, "commentInfo");
commentDataGrid.DataSource = ds.Tables["commentInfo"].DefaultView;
commentDataGrid.DataBind();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -