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