📄 bookupdata.aspx.cs
字号:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.OleDb;
public partial class Bookupdata : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
String strCon = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath("book.mdb");
OleDbConnection con = new OleDbConnection(strCon);
OleDbCommand cmd = con.CreateCommand();
cmd.CommandText = "select Bookid from Book order by Bookid asc";
con.Open();
OleDbDataReader dr = cmd.ExecuteReader();
DropDownList1.DataSource = dr;
DropDownList1.DataTextField = "Bookid";
DropDownList1.DataBind();
con.Close();
}
}
protected void Button1_Click(object sender, EventArgs e)
{
String strCon = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath("book.mdb");
OleDbConnection con = new OleDbConnection(strCon);
OleDbCommand cmd = con.CreateCommand();
cmd.CommandText = "update Book set Bookname='" + TextBox1.Text + "',Booktitle='" + TextBox2.Text + "',Bookpublish='" + TextBox3.Text + "',Bookintro='" + TextBox4.Text + "',BookisBn='" + TextBox5.Text + "',Booktime=#" + System.DateTime.Now + "# where Bookid=" + Convert.ToInt16(DropDownList1.SelectedItem.Text) ;
con.Open();
cmd.ExecuteNonQuery();
Label1.Text = "更新成功";
con.Close();
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
String strCon = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath("book.mdb");
OleDbConnection con = new OleDbConnection(strCon);
OleDbCommand cmd = con.CreateCommand();
cmd.CommandText = "select * from Book where Bookid=" + Convert.ToInt16(DropDownList1.SelectedItem.Text);
con.Open();
OleDbDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
TextBox1.Text = dr["Bookname"].ToString();
TextBox2.Text = dr["Booktitle"].ToString();
TextBox3.Text = dr["Bookpublish"].ToString();
TextBox4.Text = dr["Bookintro"].ToString();
TextBox5.Text = dr["BookisBn"].ToString();
}
con.Close();
}
protected void Button2_Click(object sender, EventArgs e)
{
Response.Redirect("Bookinsert.aspx");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -