4.3.3数据备份: 数据备份是一个数据库软件必不可少的一部分,利用它可以把当前数据库表进行全面的备份,以备以后使用。因为在操作中可能会导致数据遭到破坏,或者是系统的原因使数据库损坏,或者是一些其它的人为原因,这样你可以用此功能把数据恢复到最后一次备份的状态,使损失做到最少,经常备份,操作起来更有安全感。 内容来自论文无忧网 www.paper51.com
①数据备份效果图 paper51.com 内容来自www.paper51.com 图4.7数据备份效果图 copyright paper51.com ②功能实现 paper51.com 界面制作相对程序来说比较简单,用到的是coolbar控件,点击按钮可以选择备份路径。然后点击数据备份即可。 copyright paper51.com 窗体初始化部分代码如下: http://www.paper51.com Dim cnn1 AsADODB.Connection http://www.paper51.com Dim rstschema AsADODB.Recordset 内容来自论文无忧网 www.paper51.com Dim strcnn AsString 内容来自论文无忧网 www.paper51.com Set cnn1 = NewADODB.Connection paper51.com
strcnn ="provider=Microsoft.jet.oledb.4.0;" & "data source="& App.Path & "\db.mdb" http://www.paper51.com cnn1.Open strcnn paper51.com Set rstschema =cnn1.OpenSchema(adSchemaTables) paper51.com
Do Untilrstschema.EOF http://www.paper51.com temp =rstschema!Table_Name copyright paper51.com If Left(temp, 1)<> "M" Then copyright paper51.com End If 内容来自论文无忧网 www.paper51.com rstschema.MoveNext paper51.com Loop 内容来自论文无忧网 www.paper51.com cnn1.Close 内容来自www.paper51.com
On Error GoTo err 内容来自论文无忧网 www.paper51.com
PathName =App.Path & "\db.MDB" paper51.com dbasize =FileLen(PathName) 内容来自www.paper51.com err: paper51.com
Exit Sub http://www.paper51.com 数据备份部分在本程序中用到了一个模块,在模块中有一个方法,dobackup。点击备份按钮后开始备份,代码如下: 内容来自www.paper51.com
If txtDestination<> "" Then 内容来自www.paper51.com DoBackup PathName,txtDestination http://www.paper51.com
MsgBox "备份成功!", , "提示" paper51.com ElseIftxtDestination = "" Then paper51.com
MsgBox "Youmust specify a distination for the backup", vbCritical copyright paper51.com
其中DoBackup为模块中已定义的方法,在这里进行调用。 内容来自论文无忧网 www.paper51.com Dobackup实现方法代码如下所示: paper51.com Dim lFileOp As Long copyright paper51.com Dim lresult As Long http://www.paper51.com Dim lFlags As Long copyright paper51.com Dim SHFileOp AsSHFILEOPSTRUCT copyright paper51.com Dim strSourceDirAs String 内容来自www.paper51.com
DimstrDestinationDir As String copyright paper51.com Screen.MousePointer= vbHourglass 内容来自www.paper51.com BackupFolderName =strDestinationPath http://www.paper51.com MkDirBackupFolderName & "\Backup - " & Format(Date,"yyyy.mm.dd") copyright paper51.com
lFileOp = FO_COPY http://www.paper51.com
lFlags = lFlagsAnd Not FOF_SILENT 内容来自www.paper51.com lFlags = lFlags OrFOF_NOCONFIRMATION 内容来自论文无忧网 www.paper51.com lFlags = lFlags OrFOF_NOCONFIRMMKDIR 内容来自论文无忧网 www.paper51.com lFlags = lFlags OrFOF_FILESONLY 内容来自论文无忧网 www.paper51.com With SHFileOp copyright paper51.com .wFunc = lFileOp http://www.paper51.com .pFrom = strSourcePath &vbNullChar 内容来自www.paper51.com .pTo = strDestinationPath& "\Backup - " & Format(Date, "yyyy.mm.dd") &vbNullChar http://www.paper51.com .fFlags = lFlags 内容来自论文无忧网 www.paper51.com End With 内容来自www.paper51.com lresult =SHFileOperation(SHFileOp) paper51.com Screen.MousePointer= vbDefault copyright paper51.com
frmBackupDba.lblStatus= "Backup Complete" http://www.paper51.com 在备份分前先要选择一个备份路径,点击…那个按钮开始进行选择,实现方法如下: copyright paper51.com Dim strTemp AsString copyright paper51.com strTemp =fBrowseForFolder(Me.hwnd, "Select backup path") copyright paper51.com If strTemp<> "" Then copyright paper51.com
txtDestination = strTemp 内容来自论文无忧网 www.paper51.com
End If 内容来自www.paper51.com 数据恢复界面同上,它的功能主要是在当前数据库遭到破坏后,可以利用它来进行数据恢复,在数据恢复前要选择所要恢复的数据库路径,如下: 内容来自论文无忧网 www.paper51.com Dim strTemp AsString paper51.com strTemp =fBrowseForFolder(Me.hwnd, "Restore From") http://www.paper51.com
If strTemp<> "" Then http://www.paper51.com txtSource = strTemp copyright paper51.com dbasize2 = FileLen(txtSource& "\db.MDB") paper51.com lblSelectedDba ="Selected Backup Database is : " & Format((dbasize2 / 1024) /1024, "standard") & "MB." copyright paper51.com cmdRestore.Enabled = True 内容来自www.paper51.com
End If http://www.paper51.com Erro: copyright paper51.com
Select Case err.Number 内容来自www.paper51.com Case 53'File Not Found http://www.paper51.com
lblSelectedDba = "No Backup at this location" 内容来自论文无忧网 www.paper51.com
Toolbar2.Enabled = False copyright paper51.com End Select 内容来自www.paper51.com |