23/12/2011

How to restore backed up data in Vb.net application database? Vb.Net Computer programming Code for beginners

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:
And Code
Try
            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", _
                        MessageBoxButtons.OKCancel, _
                        MessageBoxIcon.Question, _
                        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")
            End If
        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)
        End Try

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



2 comments:

  1. Hello! I tried your codes, the backup works just fine but whenever I try to restore the database, well it says "Database Restoration Successful" but the data that I have added after backing up are still there even after restoring it to its previous conditions. What should i do? Thanks.

    ReplyDelete
  2. just check the location of your database.

    ReplyDelete

What & How