?? 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 + -