zoukankan      html  css  js  c++  java
  • 备份与恢复ACCESS数据库

    备份与恢复ACCESS数据库
    核心技术:
    File.Copy

    1.前台
           <table>
              <tr>
                <td align="center" colspan="3" style="height: 19px"><strong><span style="font-size: 12pt">备份与恢复ACCESS数据库</span></strong></td>
                </tr>
                <tr>
                    <td style=" 192px">数据库备份名称:</td>
                    <td><asp:TextBox ID="TextBox1" runat="server" Columns="17" MaxLength="17"></asp:TextBox></td>
                    <td><asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="数据备份" /></td>
                </tr>
                <tr>
                    <td style=" 192px">数据库恢复名称:</td>
                    <td><asp:DropDownList ID="DropDownList1" runat="server" Width="153px"></asp:DropDownList></td>
                    <td><asp:Button ID="Button2" runat="server" OnClick="Button2_Click" Text="数据恢复" /></td>
                </tr>
            </table>
    2.后台

    using System.IO;
    using System.Data.SqlClient;

    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                TextBox1.Text = DateTime.Now.ToShortDateString()+DateTime.Now.Hour.ToString() + "H.mdb";
                this.DataBindList();
            }
        }
        protected void Button1_Click(object sender, EventArgs e)
        {
            if (!File.Exists(Server.MapPath(@"~\bakDataBase\" + TextBox1.Text)))
            {
                File.Copy(Server.MapPath(@"~\App_Data\Test.mdb"), Server.MapPath(@"~\bakDataBase\" + TextBox1.Text));
                this.DataBindList();
                Response.Write("数据备份成功!");
            }
            else
            {
                Response.Write("备份文件已经存在,请重新命名!!!");
            }
        }
        public void DataBindList()
        {
            DropDownList1.Items.Clear();
            DataTable dt = new DataTable();
            dt.Columns.Add(new DataColumn("fileName", typeof(string)));
            DirectoryInfo dir = new DirectoryInfo(Server.MapPath(@"~\bakDataBase\"));
            foreach (FileInfo file in dir.GetFiles())
            {
                DataRow dr = dt.NewRow();
                dr[0] = file;
                dt.Rows.Add(dr);
            }
            DropDownList1.DataSource = dt;
            DropDownList1.DataTextField = "fileName";
            DropDownList1.DataBind();
        }
        protected void Button2_Click(object sender, EventArgs e)
        {
            File.Copy(Server.MapPath(@"~\bakDataBase\" + DropDownList1.SelectedItem.Text), Server.MapPath(@"~\App_Data\Test.mdb"), true);
            Response.Write("数据恢复成功!");
        }
    }

  • 相关阅读:
    【科创人上海行】扶墙老师王福强:架构师创业要突破思维局限,技术人创业的三种模式,健康第一
    【科创人·独家】连续创业者高春辉的这六年:高强度投入打造全球领先的IP数据库
    中国确实需要大力扩充核武器
    SAP MM 可以通过STO在公司间转移质检库存?
    SAP MM 如何看一个采购申请是由APO系统创建后同步过来的?
    SAP MM 如何看一个Inbound Delivery单据相关的IDoc?
    SAP ECC & APO集成
    SAP MM 采购订单收货之后自动形成分包商库存?
    SAP MM 带有'Return'标记的STO,不能创建内向交货单?
    SAP MM 没有启用QM的前提下可以从QI库存里退货给Vendor?
  • 原文地址:https://www.cnblogs.com/astar/p/956223.html
Copyright © 2011-2022 走看看