Default.aspx

View Code
 1 <%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>
 2 
 3 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 4 
 5 <html xmlns="http://www.w3.org/1999/xhtml" >
 6 <head id="Head1" runat="server">
 7     <title>与加密后的Access数据库建立连接</title>
 8 </head>
 9 <body>
10     <form id="form1" runat="server">
11     <div>
12         <div style="text-align: center">
13             <table style="width: 587px; height: 338px">
14                 <tr>
15                     <td colspan="6">
16                         <asp:Image ID="Image1" runat="server" ImageUrl="~/image/head.gif" /></td>
17                 </tr>
18                 <tr>
19                     <td style="width: 100px; height: 13px">
20                         <asp:Label ID="Label1" runat="server" Font-Size="Smaller" Text="输入连接Access数据库的密码:"
21                             Width="199px"></asp:Label></td>
22                     <td style="width: 77px; height: 13px">
23                         <asp:TextBox ID="TxtMm" runat="server" TextMode="Password"></asp:TextBox></td>
24                     <td style="width: 77px; height: 13px">
25                         <asp:Button ID="BtnOK" runat="server" OnClick="BtnOK_Click" Text="显示数据" Width="58px" /></td>
26                     <td style="width: 100px; height: 13px">
27                         <asp:Label ID="lblMessage" runat="server" Font-Bold="True" Font-Size="Smaller" ForeColor="Red"
28                             Width="296px"></asp:Label></td>
29                     <td style="width: 100px; height: 13px">
30                         &nbsp;</td>
31                     <td style="width: 95px; height: 13px">
32                     </td>
33                 </tr>
34                 <tr>
35                     <td colspan="6" style="height: 142px">
36                         <asp:GridView ID="GridbookSell" runat="server" AutoGenerateColumns="False" CellPadding="4"
37                             Font-Size="Smaller" ForeColor="#333333" GridLines="None" Width="788px">
38                             <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
39                             <Columns>
40                                 <asp:BoundField DataField="图书编号" HeaderText="图书编号" />
41                                 <asp:BoundField DataField="图书名称" HeaderText="图书名称" />
42                                 <asp:BoundField DataField="价格" HeaderText="价格" />
43                                 <asp:BoundField DataField="出版时间" HeaderText="出版时间" />
44                                 <asp:BoundField DataField="类别" HeaderText="类别" />
45                                 <asp:BoundField DataField="备注" HeaderText="备注" />
46                             </Columns>
47                             <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
48                             <EditRowStyle BackColor="#999999" />
49                             <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
50                             <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
51                             <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
52                             <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
53                         </asp:GridView>
54                     </td>
55                 </tr>
56                 <tr>
57                     <td colspan="6" style="height: 60px">
58                         <asp:Image ID="Image2" runat="server" ImageUrl="~/image/foot.gif" /></td>
59                 </tr>
60             </table>
61         </div>
62     
63     </div>
64     </form>
65 </body>
66 </html>

Default.aspx.cs

View Code
 1 using System;
 2 using System.Configuration;
 3 using System.Data;
 4 using System.Linq;
 5 using System.Web;
 6 using System.Web.Security;
 7 using System.Web.UI;
 8 using System.Web.UI.HtmlControls;
 9 using System.Web.UI.WebControls;
10 using System.Web.UI.WebControls.WebParts;
11 using System.Xml.Linq;
12 
13 using System.Data.OleDb;
14 public partial class _Default : System.Web.UI.Page
15 {
16     protected void Page_Load(object sender, EventArgs e)
17     {
18 
19     }
20     protected void BtnOK_Click(object sender, EventArgs e)
21     {
22         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");
23         OleDbConnection Con = new OleDbConnection(ConStr);
24         if (this.TxtMm.Text == "")
25         {
26             Response.Write("<script language=javascript>alert('对不起!文本框不能为空!');location='javascript:history.go(-1)'</script>");
27         }
28         else
29         {
30             try
31             {
32                 //打开数据库连接
33                 Con.Open();
34                 OleDbDataAdapter Dap = new OleDbDataAdapter("select * from tb_booksell", Con);
35                 DataSet ds = new DataSet();
36                 Dap.Fill(ds, "tb_booksell");
37                 GridbookSell.DataSource = ds;
38                 GridbookSell.DataBind();
39                 this.lblMessage.Text = " 恭喜你,与加密后的Access数据库连接成功!";
40             }
41             catch (Exception error)
42             {
43                 this.lblMessage.Text = " 很遗憾,密码错误,请重新输入密码!";
44                 return;
45             }
46             finally
47             {
48                 //关闭数据库连接
49                 Con.Close();
50             }
51         }
52 
53     }
54 }

 

posted on 2013-03-09 23:48  松竹梅  阅读(306)  评论(0编辑  收藏  举报