Foxtable(狐表)用户栏目专家坐堂 → 求助access恢复命令简化代码


  共有10341人关注过本帖树形打印复制链接

主题:求助access恢复命令简化代码

帅哥哟,离线,有人找我吗?
bl018
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:幼狐 帖子:126 积分:1437 威望:0 精华:0 注册:2009/1/27 10:06:00
求助access恢复命令简化代码  发帖心情 Post By:2012/2/18 20:44:00 [只看该作者]

如下代码请各位大侠帮手如何简化一下,"恢复access数据库备份"命令如下:

       

'恢复数据库

Dim Result As DialogResult

Result = MessageBox.Show("数据恢复将破坏现有数据库,继续吗?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question)

If Result = DialogResult.Yes Then 

    Dim dlg As New OpenFileDialog '定一个新的OpenFileDialog

dlg.Filter= "备份文件|*.mdbc" '设置筛选器

 

    If dlg.ShowDialog = DialogResult.Ok Then     '如果用户单击了确定按钮

        Dim fc As String=dlg.FileName     

        Dim f As String=fc.TrimEnd("c")          '指定的要删除”c”的字符

        DecryptFile(fc,f, "fox")                 '用于解密EncryptFile函数加密后的文件,

 

            DataTables("帐务处理").DataRows.Clear()

            DataTables("users").DataRows.Clear()

            DataTables("功能分类").DataRows.Clear()

            DataTables("单位").DataRows.Clear()

            DataTables("归口类型").DataRows.Clear()

            DataTables("授权表").DataRows.Clear()

            DataTables("归口类型").DataRows.Clear()

             DataTables("收支汇总表").DataRows.Clear()

             DataTables("文件管理").DataRows.Clear()

            DataTables("正常经费收支情况表").DataRows.Clear()

            DataTables("水利专户").DataRows.Clear()

            DataTables("水库经营性收支表").DataRows.Clear()

            DataTables("科股室").DataRows.Clear()

            DataTables("项目设置").DataRows.Clear()

            DataTables("预算类型").DataRows.Clear()

            DataTables("项目设置").DataRows.Clear()

 

         Dim mg As New Merger

            mg.SourcePath = f

            mg.PassWord="sir"

            mg.SourceTableName = "帐务处理"

            mg.DataTableName = "帐务处理"

            mg.Merge()

          

        Dim mg2 As New Merger

             Mg2.SourcePath = f

            Mg2.PassWord="sir"

            Mg2.SourceTableName = "users"

            Mg2.DataTableName = " users"

            Mg2.Merge()

          

       Dim mg3 As New Merger

            Mg3.SourcePath = f

            Mg3.PassWord="sir"

            Mg3.SourceTableName = "功能分类"

            Mg3.DataTableName = "功能分类"

            Mg3.Merge()

 

       Dim mg4 As New Merger

            Mg4.SourcePath = f

            Mg4.PassWord="sir"

            Mg4.SourceTableName = "单位"

            Mg4.DataTableName = "单位"

            Mg4.Merge()

 

         Dim mg5 As New Merger

            Mg5.SourcePath = f

            Mg5.PassWord="sir"

            Mg5.SourceTableName = "归口类型"

            Mg5.DataTableName = "归口类型"

            Mg5.Merge()

 

        Dim mg6 As New Merger

            Mg6.SourcePath = f

            Mg6.PassWord="sir"

            Mg6.SourceTableName = "授权表 "

            Mg6.DataTableName = "授权表"

            Mg6.Merge()

 

        Dim mg7 As New Merger

            Mg7.SourcePath = f

            Mg7.PassWord="sir"

            Mg7.SourceTableName = "收支汇总表"

            Mg7.DataTableName = "收支汇总表"

            Mg7.Merge()

 

        Dim mg8 As New Merger

            Mg8.SourcePath = f

            Mg8.PassWord="sir"

            Mg8.SourceTableName = "文件管理 "

            Mg8.DataTableName = "文件管理"

            Mg8.Merge()

 

       Dim mg9 As New Merger

            Mg9.SourcePath = f

            Mg9.PassWord="sir"

            Mg9.SourceTableName = "正常经费收支情况表 "

            Mg9.DataTableName = "正常经费收支情况表"

            Mg9.Merge()

 

      Dim mg10 As New Merger

            Mg10.SourcePath = f

            Mg10.PassWord="sir"

            Mg10.SourceTableName = "水利专户"

            Mg10.DataTableName = "水利专户"

            Mg10.Merge()

      Dim mg11 As New Merger

            Mg11.SourcePath = f

            Mg11.PassWord="sir"

            Mg11.SourceTableName = "水库经营性收支表"

            Mg11.DataTableName = "水库经营性收支表"

            Mg11.Merge()

       Dim mg12 As New Merger

            Mg12.SourcePath = f

            Mg12.PassWord="sir"

            Mg12.SourceTableName = "科股室 "

            Mg12.DataTableName = "科股室"

            Mg12.Merge()

            Dim mg13 As New Merger

            Mg13.SourcePath = f

            Mg13.PassWord="sir"

            Mg13.SourceTableName = "项目设置"

            Mg13.DataTableName = "项目设置"

            Mg13.Merge()

         Dim mg14 As New Merger

            Mg14.SourcePath = f

            Mg14.PassWord="sir"

            Mg14.SourceTableName = "预算类型 "

            Mg14.DataTableName = "预算类型"

            Mg14.Merge()

       Dim mg15 As New Merger

            Mg15.SourcePath = f

            Mg15.PassWord="sir"

            Mg15.SourceTableName = "预算草案"

            Mg15.DataTableName = "预算草案"

            Mg15.Merge()

 

            FileSys.DeleteFile(f,2,2)       ‘删除f文件

            MessageBox.Show("数据导入成功!")

        End If

End If


 回到顶部
帅哥哟,离线,有人找我吗?
bl018
  2楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:幼狐 帖子:126 积分:1437 威望:0 精华:0 注册:2009/1/27 10:06:00
  发帖心情 Post By:2012/2/18 20:49:00 [只看该作者]

上述是学民通仓管系统的恢复ACCESS数据备份,,,

      他的ACCESS数据备份代码我简化成如下(可以做为ACCESS外部数据源数据备份-通用代码):

   

'Access数据库备份

Dim f As String

Dim fc As String

Dim rqf As Date = Date.today

Dim rq As String=Format(rqf, "yyyyMMdd")

Dim q As Date = Date.now

Dim s As String=Format(q, "HHmmss")

 

Dim Names As List(Of String)

Names= Connections("blny2011").GetTableNames

For Each name As String In Names  

Dim ex As New Exporter

    ex.SourceTableName = name '指定导出表

    ex.filepath = ProjectPath & "backup" & "\" & rq & "-" & s & ".mdb" '指定目录(backup)目标文件

    ex.PassWord="sir"  

    ex.Export() '开始导出

    f=ex.filepath

    fc=f & "c"

Next

EncryptFile(f, fc, "fox")    '生成一个加密文件,加密密码为foX

FileSys.DeleteFile(f,2,2)     '将f  文件则彻底删除之

MessageBox.Show("备份数据保存成功!" & fc)


 回到顶部
帅哥哟,离线,有人找我吗?
bl018
  3楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:幼狐 帖子:126 积分:1437 威望:0 精华:0 注册:2009/1/27 10:06:00
  发帖心情 Post By:2012/2/18 23:57:00 [只看该作者]

如果是几十个表要备份那要远长代码,所以征集各位简化的代码用用图片点击可在新窗口打开查看


 回到顶部
帅哥哟,离线,有人找我吗?
czy
  4楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信 一级勋章 三级勋章 二级勋章
等级:超级版主 帖子:6318 积分:33963 威望:0 精华:10 注册:2008/8/31 20:56:00
  发帖心情 Post By:2012/2/19 8:09:00 [只看该作者]

这样?

 

Dim Names() As String  = {"帐务处理", "users","功能分类","单位","归口类型","授权表","收支汇总表","文件管理","正常经费收支情况表","水利专户","水库经营性收支表","科股室","项目设置","预算类型","预算草案"}
For Each Name As String In Names

    DataTables(Name).DataRows.Clear()
    Dim mg As New Merger
    mg.SourcePath = f
    mg.PassWord="sir"
    mg.SourceTableName = Name
    mg.DataTableName = Name
    mg.Merge()
Next

[此贴子已经被作者于2012-2-19 8:16:06编辑过]

 回到顶部
帅哥哟,离线,有人找我吗?
bl018
  5楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:幼狐 帖子:126 积分:1437 威望:0 精华:0 注册:2009/1/27 10:06:00
  发帖心情 Post By:2012/2/19 20:58:00 [只看该作者]

3Q 


 回到顶部
帅哥哟,离线,有人找我吗?
bl018
  6楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:幼狐 帖子:126 积分:1437 威望:0 精华:0 注册:2009/1/27 10:06:00
  发帖心情 Post By:2012/2/19 21:00:00 [只看该作者]

请问这个可以改不

Dim Names() As String  = {"帐务处理", "users","功能分类","单位","归口类型","授权表","收支汇总表","文件管理","正常经费收支情况表","水利专户","水库经营性收支表","科股室","项目设置","预算类型","预算草案"}

好象用下面的换不了

    

Dim Names As List(Of String)

Names= Connections("blny2011").GetTableNames

For Each name As String In Names  


 回到顶部
帅哥哟,离线,有人找我吗?
czy
  7楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信 一级勋章 三级勋章 二级勋章
等级:超级版主 帖子:6318 积分:33963 威望:0 精华:10 注册:2008/8/31 20:56:00
  发帖心情 Post By:2012/2/20 7:56:00 [只看该作者]

直接这样就可以遍历了

 

For Each name As String In Connections("blny2011").GetTableNames
    Output.Show(name)
Next


 回到顶部