Database Restore in vb.net

Database Restore in vb.net
firstly you need to add reference to COM component: Microsoft DAO Object Library to your project.
Project menu -> Add Reference -> COM tab -> Navigate to "Microsoft DAO 3.x Object Library
====================================================
Microsoft DAO Object Library to your project

Imports System.IO
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim sDBFile As String = Application.StartupPath + "/db_name.mdb"
Dim sBackUpFile As String = "E:\db_name.mdb"

'Restore the original file from the compacted file
If File.Exists(sBackUpFile) Then
File.Copy(sBackUpFile, sDBFile, True)
End If
End Sub
End Class
==============================================================

Easy method (simple method)
----------------------------------------------------------------------------------------------------
Imports System.IO
……………………………………………………………………………………………………………………………….
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim sDBFile As String = Application.StartupPath + "/db_name.mdb"
Dim sBackUpFile As String = "E:\db_name.mdb ‘any path
If File.Exists(sBackUpFile) Then
FileCopy(sBackUpFile, sDBFile)
End If
End Sub
End Class
===============================================================

No comments: