qileilove

          blog已經轉移至github,大家請訪問 http://qaseven.github.io/

          與加密后的Access數據庫建立連接

            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>
          <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();
          }
          }
          }
          }

          posted on 2014-07-15 10:30 順其自然EVO 閱讀(181) 評論(0)  編輯  收藏 所屬分類: 數據庫

          <2014年7月>
          293012345
          6789101112
          13141516171819
          20212223242526
          272829303112
          3456789

          導航

          統計

          常用鏈接

          留言簿(55)

          隨筆分類

          隨筆檔案

          文章分類

          文章檔案

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 奉节县| 邹城市| 甘德县| 庐江县| 望都县| 容城县| 大关县| 大庆市| 湄潭县| 荃湾区| 呼图壁县| 邵武市| 那坡县| 波密县| 旬邑县| 正安县| 浦北县| 淮阳县| 上蔡县| 大安市| 湖州市| 黑河市| 浑源县| 新竹县| 贡嘎县| 柘荣县| 平陆县| 仲巴县| 姜堰市| 民丰县| 蕲春县| 塔城市| 嫩江县| 察雅县| 如皋市| 威远县| 贵定县| 宜兰县| 固原市| 太仆寺旗| 顺昌县|