?? updatenews.aspx.cs
字號:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Data.OleDb;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
namespace news
{
/// <summary>
/// Xiu1 的摘要說明。
/// </summary>
public partial class UpdateNews : System.Web.UI.Page
{
DataRow dr; //數據視圖
string newsid; //新聞編號
string strDBPath; //數據庫存儲路徑
string strConn; //數據庫連接
protected void Page_Load(Object sender, EventArgs e)
{
strDBPath = System.Configuration.ConfigurationSettings.AppSettings["DBPath"];
strConn = System.Configuration.ConfigurationSettings.AppSettings["Connection"] + Server.MapPath(strDBPath);
if(!IsPostBack)
{
//創建數據庫連接,根據新聞編號獲取新聞信息
newsid = Request.Params["id"];
OleDbConnection myConnection = new OleDbConnection(strConn);
OleDbDataAdapter myCommand = new OleDbDataAdapter("SELECT * FROM News WHERE id="+newsid, myConnection);
DataSet ds = new DataSet();
myCommand.Fill(ds, "News");
dr = ds.Tables["News"].Rows[0];
//顯示新聞信息
Title.Text=dr["Title"].ToString();
Content.Text=dr["Content"].ToString();
Auth.Text=dr["Auth"].ToString();
}
}
//更新數據庫,保存新聞信息
public void Button1_Click(object Source, EventArgs e)
{
newsid = Request.Params["id"];
OleDbConnection myConnection = new OleDbConnection(strConn);
OleDbCommand myCommand = new OleDbCommand("UPDATE News set Title='" + Title.Text + "', Content='" + Content.Text + "',Auth='" + Auth.Text +"' WHERE id="+newsid, myConnection);
myCommand.Connection.Open();
myCommand.ExecuteNonQuery();
myCommand.Connection.Close();
Response.Redirect("ManageNews.aspx") ;
}
#region Web 窗體設計器生成的代碼
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 該調用是 ASP.NET Web 窗體設計器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 設計器支持所需的方法 - 不要使用代碼編輯器修改
/// 此方法的內容。
/// </summary>
private void InitializeComponent()
{
}
#endregion
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -