与加密后的Access数据库建立连接

Trixie ·
更新时间:2024-11-13
· 849 次阅读

Default.aspx
<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <head id="Head1" runat="server"> <title>与加密后的Access数据库建立连接</title> </head> <body> <form id="form1" runat="server"> <div> <div style="text-align: center"> <table style="width: 587px; height: 338px"> <tr> <td colspan="6"> <asp:Image ID="Image1" runat="server" ImageUrl="~/image/head.gif" /></td> </tr> <tr> <td style="width: 100px; height: 13px"> <asp:Label ID="Label1" runat="server" Font-Size="Smaller" Text="输入连接Access数据库的密码:" Width="199px"></asp:Label></td> <td style="width: 77px; height: 13px"> <asp:TextBox ID="TxtMm" runat="server" TextMode="Password"></asp:TextBox></td> <td style="width: 77px; height: 13px"> <asp:Button ID="BtnOK" runat="server" OnClick="BtnOK_Click" Text="显示数据" Width="58px" /></td> <td style="width: 100px; height: 13px"> <asp:Label ID="lblMessage" runat="server" Font-Bold="True" Font-Size="Smaller" ForeColor="Red" Width="296px"></asp:Label></td> <td style="width: 100px; height: 13px"> </td> <td style="width: 95px; height: 13px"> </td> </tr> <tr> <td colspan="6" style="height: 142px"> <asp:GridView ID="GridbookSell" runat="server" AutoGenerateColumns="False" CellPadding="4" Font-Size="Smaller" ForeColor="#333333" GridLines="None" Width="788px"> <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" /> <Columns> <asp:BoundField DataField="图书编号" HeaderText="图书编号" /> <asp:BoundField DataField="图书名称" HeaderText="图书名称" /> <asp:BoundField DataField="价格" HeaderText="价格" /> <asp:BoundField DataField="出版时间" HeaderText="出版时间" /> <asp:BoundField DataField="类别" HeaderText="类别" /> <asp:BoundField DataField="备注" HeaderText="备注" /> </Columns> <RowStyle BackColor="#F7F6F3" ForeColor="#333333" /> <EditRowStyle BackColor="#999999" /> <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" /> <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" /> <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" /> <AlternatingRowStyle BackColor="White" ForeColor="#284775" /> </asp:GridView> </td> </tr> <tr> <td colspan="6" style="height: 60px"> <asp:Image ID="Image2" runat="server" ImageUrl="~/image/foot.gif" /></td> </tr> </table> </div> </div> </form> </body> </html>
  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(); } } } }

 



加密 连接 access数据库 access

需要 登录 后方可回复, 如果你还没有账号请 注册新账号