In my previous post I have written about the VB.Net code for taking back up from an application database. Knowing the way for restoring the backed up data in a database in as important as taking backup. And action in both the case is opposite to each others. In backup we copy the data from an application database to other directory or folder of a computer where in restoring, we are copy the data from that folder or directory to application database. For better understanding of these type of vb.net code or database related inquiry the book written by Mike Murach is very good book which is available on amazon with free shipping charge, I will suggest one can be refer
The VB.net code for restoring data to an application database is more simple and very small compare to taking backup of the database. So using the folder and MS-access database of my previous post, the Vb.net code for restoring is as under:
Dim portfolioPath As String = My.Application.Info.DirectoryPath
If MessageBox.Show("Restoring the database will erase any changes you have made since you last backup. Are you sure you want to do this?", _
"Confirm Delete", _
MessageBoxDefaultButton.Button2) = Windows.Forms.DialogResult.OK Then
'Restore the database from a backup copy.
FileCopy("C:\Backup\PIS.Mdb", portfolioPath & "\PIS.mdb")
MsgBox("Database Restoration Successful")
Catch ex As Exception
Dim MessageString As String = "Report this error to the system administrator: " & ControlChars.NewLine & ex.Message
Dim TitleString As String = "Employee Master Details Data Load Failed"
MessageBox.Show(MessageString, TitleString, MessageBoxButtons.OK, MessageBoxIcon.Error)
For bettering understanding of this code it is suggested to read my post for taking backup:
How to take Backup and also It is suggested to have a book written by Anne Prince which is available on Amazon as well as Flipkart