0% found this document useful (0 votes)
124 views4 pages

Membuat Backup Database Dengan VB Net

The document discusses two methods for creating database backups in VB.NET 2005. The first method involves using a form with drive, directory, and file list boxes to select a source file and destination path. The file is then copied using the CopyFile method. The second method uses open and save dialog boxes along with buttons to select the source file, destination folder, and copy the file. Both methods provide the essential coding for copying a database file with VB.NET.

Uploaded by

Uus Rusmawan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
124 views4 pages

Membuat Backup Database Dengan VB Net

The document discusses two methods for creating database backups in VB.NET 2005. The first method involves using a form with drive, directory, and file list boxes to select a source file and destination path. The file is then copied using the CopyFile method. The second method uses open and save dialog boxes along with buttons to select the source file, destination folder, and copy the file. Both methods provide the essential coding for copying a database file with VB.NET.

Uploaded by

Uus Rusmawan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

www.konsultasivb.

com
Oleh : Uus Rusmawan Hal - 1 –

MEMBUAT BACKUP DATABASE DI VB.NET 2005


Buatlah form seperti gambar di bawah ini (terdiri dari) :
1. groupbox
2. drivelistbox
3. dirlistbox
4. filelistbox
5. label
6. textbox
7. button

Coding :

Public Class SalinFile

Private Sub DriveListBox1_SelectedIndexChanged(ByVal sender As


System.Object, ByVal e As System.EventArgs) Handles
DriveListBox1.SelectedIndexChanged
DirListBox1.Path = DriveListBox1.Drive
End Sub

Private Sub DirListBox1_SelectedIndexChanged(ByVal sender As


System.Object, ByVal e As System.EventArgs) Handles
DirListBox1.SelectedIndexChanged
FileListBox1.Path = DirListBox1.Path
End Sub
www.konsultasivb.com
Oleh : Uus Rusmawan Hal - 2 –

Private Sub FileListBox1_SelectedIndexChanged(ByVal sender As


System.Object, ByVal e As System.EventArgs) Handles
FileListBox1.SelectedIndexChanged
TextBox1.Text = FileListBox1.Path & "\" & FileListBox1.FileName
End Sub

Private Sub DriveListBox2_SelectedIndexChanged(ByVal sender As


System.Object, ByVal e As System.EventArgs) Handles
DriveListBox2.SelectedIndexChanged
DirListBox2.Path = DriveListBox2.Drive
End Sub

Private Sub DirListBox2_SelectedIndexChanged(ByVal sender As


System.Object, ByVal e As System.EventArgs) Handles
DirListBox2.SelectedIndexChanged
TextBox2.Text = DirListBox2.Path & "\" & FileListBox1.FileName
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button1.Click
Try
If TextBox1.Text = "" Then
MsgBox("Anda belum memilih file yang akan dicopy")
Exit Sub
ElseIf TextBox2.Text = "" Then
MsgBox("Anda tidak memilih direktori tujuan peng-Copy-
an")
Exit Sub
End If
My.Computer.FileSystem.CopyFile(TextBox1.Text,
TextBox2.Text) ---- INTI CODING ADA DISINI
MsgBox("Copy File sukses")
TextBox1.Clear()
TextBox2.Clear()
Catch ex As Exception
MsgBox(ex.Message)
End Try

End Sub

Private Sub BackupDatabase_Load(ByVal sender As System.Object,


ByVal e As System.EventArgs) Handles MyBase.Load
TextBox1.Clear()
TextBox2.Clear()
DriveListBox1.Drive = "C:\"
DriveListBox2.Drive = "C:\"
FileListBox1.FileName = ""
End Sub

End Class
www.konsultasivb.com
Oleh : Uus Rusmawan Hal - 3 –

CARA LAIN MEMBUAT BACKUP DATABASE :


Buatlah form seperti gambar di dawah ini (terdiri dari)
1. button
2. textbox
3. filelistbox
4. browsefolderdialog (tidak terlihat >> di bagian bawah form) lalu ganti nama
dengan (bukafolder)
5. openfiledialog (tidak terlihat >> di bagian bawah form), kemudian ganti nama
dengan (carifile)

Coding :
Public Class salinlagi

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button1.Click
On Error Resume Next
CariFile.ShowDialog()
CariFile.Filter = "(*.mdb) |*.mdb"
TextBox1.Text = CariFile.FileName
FileListBox1.FileName = CariFile.FileName
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button2.Click
bukafolder.ShowDialog()
TextBox2.Text = bukafolder.SelectedPath & "\" &
FileListBox1.FileName
End Sub
www.konsultasivb.com
Oleh : Uus Rusmawan Hal - 4 –

Private Sub salinlagi_Load(ByVal sender As System.Object, ByVal e


As System.EventArgs) Handles MyBase.Load
FileListBox1.FileName = Nothing
FileListBox1.FileName = ""
End Sub

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button3.Click
Try
If TextBox1.Text = "" Then
MsgBox("Anda belum memilih file yang akan dicopy")
Exit Sub
ElseIf TextBox2.Text = "" Then
MsgBox("Anda tidak memilih direktori tujuan peng-Copy-
an")
Exit Sub
End If
My.Computer.FileSystem.CopyFile(TextBox1.Text,
TextBox2.Text) ---- INTI CODING ADA DISINI
MsgBox("Copy File sukses")
TextBox1.Text = ""
TextBox2.Text = ""
Catch ex As Exception
MsgBox(ex.Message)
End Try

End Sub
End Class

You might also like