Default.aspx.cs
using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.OleDb;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void BtnOK_Click(object sender, EventArgs e)
{
string ConStr = "Provider=Microsoft.Jet.OLEDB.4.0;Jet OLEDB:DataBase Password=" + this.TxtMm.Text + ";User Id=admin;Data source=" + Server.MapPath("db_ADO.mdb");
OleDbConnection Con = new OleDbConnection(ConStr);
if (this.TxtMm.Text == "")
{
Response.Write("<script language=javascript>alert('对不起!文本框不能为空!');location='javascript:history.go(-1)'</script>");
}
else
{
try
{
//打开数据库连接
Con.Open();
OleDbDataAdapter Dap = new OleDbDataAdapter("select * from tb_booksell", Con);
DataSet ds = new DataSet();
Dap.Fill(ds, "tb_booksell");
GridbookSell.DataSource = ds;
GridbookSell.DataBind();
this.lblMessage.Text = " 恭喜你,与加密后的Access数据库连接成功!";
}
catch (Exception error)
{
this.lblMessage.Text = " 很遗憾,密码错误,请重新输入密码!";
return;
}
finally
{
//关闭数据库连接
Con.Close();
}
}
}
}