使用vb.net备份访问数据库 [英] access database with vb.net backup

查看:79
本文介绍了使用vb.net备份访问数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人请帮我备份我在vb.net上的访问数据库。

我有这个代码,它在我的电脑上运行良好但是当我在另一台PC上安装它不起作用时,它无法找到数据库。



代码:

dim path as string = my.application.info。 directorypath

filecopy(路径&\ POPdatabase.mdb,D:\ backupfolder \ POOPdatabase.mdb)

解决方案

您可以使用'FolderBrowserDialog'来备份您的数据库。

喜欢这个





  Dim 文件夹作为  FolderBrowserDialog 
如果 folder.ShowDialog()= Windows.Forms.DialogResult.OK 那么
TextBoxDestination.Text = folder.SelectedPath
结束 如果



我希望它对你有帮助..


  Dim 文件夹 As   FolderBrowserDialog 
folde r.RootFolder = Environment.SpecialFolder.MyComputer
如果 folder.ShowDialog()= Windows.Forms.DialogResult.OK 然后
textbox1.Text = folder.SelectedPath
结束 如果







  Dim  path1  As   String  = Application.LocalUserAppDataPath 

FileCopy(路径1& \ databasename.sdf,textbox1.Text& \ databasename.sdf
MsgBox( 备份成功





注意:

1.代码的第一部分选择目标驱动器或文件夹

2.放置一个名为textbox1的readonly文本框(任意名称)

3.上述代码在安装已发布的设置后完美运行(.exe设置

在您的机器或客户端计算机上

它在调试时无效

让我回复






我用这段代码来备份访问数据库备份<




 Private Sub ButtonSource_Click(ByVal sender As System.Object,ByVal e As System.EventArgs)处理ButtonSource。点击
尝试
Dim dlg作为新的OpenFileDialog
dlg.InitialDirectory = Application.StartupPath
'dlg.InitialDirectory =C:\Program Files \Default Company Name\ePolitices

dlg.Filter =Microsoft Access Database(2002 -2003)(* .mdb)| * .mdb | Microsoft Access数据库(2007-2009)(* .accdb)| * .accdb
如果要保留默认扩展* .mdb,则FilterIndex = 1或者如果你想保留默认扩展* .accdb然后FilterIndex = 2
dlg.FilterIndex = 1

如果dlg.ShowDialog()= Windows.Forms.DialogResult.OK那么
TextBoxSource.Text = dlg.FileName
End if
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub


Private Sub ButtonDestination_Click(ByVal sender As System.Object,ByVal e As System.EventArgs)Handles ButtonDestination.Click
Try
Dim folder As New FolderBrowserDialog
如果folder.ShowDialog()= Windows.Forms.DialogResult.OK然后
TextBoxDestination.Text = folder.SelectedPath
结束如果
Catch ex As Exception
MessageBox。显示(ex.Message)
结束尝试
结束Sub

Private Sub ButtonBackup_Click(ByVal sender As System.Object,ByVal e As System.EventArgs)处理ButtonBackup.Click
尝试
如果TextBoxSource.Text =那么
MessageBox.Show(请选择数据库源。)
ButtonSource.Focus()
退出Sub
结束如果
如果TextBoxDestination.Text =那么
MessageBox.Show(请选择数据库目的地。)
ButtonDestination.Focus()
退出Sub
结束如果
If TextBoxFileName.Text =那么
MessageBox.Show(请输入文件名。)
TextBoxFileName.Focus()
退出Sub
结束如果

Dim ext As String
ext = TextBoxSource.Text.Substring(TextBoxSource.Text.IndexOf( 。)+ 1)

File.Copy(TextBoxSource.Text,TextBoxDestination.Text& \& TextBoxFileName.Text& &安培; $)

MessageBox.Show(成功备份数据库。)
Catch ex As Exception
MessageBox.Show(ex.Message)
结束尝试
结束子







我希望这对你有所帮助....... ...


Someone please help me back up my access database in vb.net.
I have this code and it works well on my computer but when I install the setup on a different PC it doesnt work, its not able to locate the database.

code:
dim path as string = my.application.info. directorypath
filecopy(path & "\POPdatabase.mdb", "D:\backupfolder\POPdatabase.mdb")

解决方案

You can use the 'FolderBrowserDialog' to take the backup of your database.
Like this


Dim folder As New FolderBrowserDialog
          If folder.ShowDialog() = Windows.Forms.DialogResult.OK Then
              TextBoxDestination.Text = folder.SelectedPath
          End If


I hope it is helpful for you..


Dim folder As New FolderBrowserDialog
       folder.RootFolder = Environment.SpecialFolder.MyComputer
       If folder.ShowDialog() = Windows.Forms.DialogResult.OK Then
           textbox1.Text = folder.SelectedPath
       End If




Dim path1 As String = Application.LocalUserAppDataPath
          
               FileCopy(path1 & "\databasename.sdf", textbox1.Text & "\databasename.sdf")
               MsgBox("Backup successful")



Note:
1. the first part of the code selects the destination drive or folder
2. place a readonly textbox called textbox1 (any name)
3. the above code works perfectly after installing the published setup (.exe setup
either on your machine or client machine
it would not work when debuging
Let me have your responds


Hi,

I used this code for taking backup of access data base backup


Private Sub ButtonSource_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonSource.Click
        Try
            Dim dlg As New OpenFileDialog
            dlg.InitialDirectory = Application.StartupPath
            'dlg.InitialDirectory = "C:\Program Files\Default Company Name\ePolitices"

            dlg.Filter = "Microsoft Access Database(2002-2003) (*.mdb)|*.mdb|Microsoft Access Database(2007-2009) (*.accdb)|*.accdb"
            ' If you want to keep default extensiion *.mdb then FilterIndex = 1 or if you want to keep default extension *.accdb then FilterIndex=2
            dlg.FilterIndex = 1

            If dlg.ShowDialog() = Windows.Forms.DialogResult.OK Then
                TextBoxSource.Text = dlg.FileName
            End If
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Sub


    Private Sub ButtonDestination_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonDestination.Click
        Try
            Dim folder As New FolderBrowserDialog
            If folder.ShowDialog() = Windows.Forms.DialogResult.OK Then
                TextBoxDestination.Text = folder.SelectedPath
            End If
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Sub

    Private Sub ButtonBackup_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonBackup.Click
        Try
            If TextBoxSource.Text = "" Then
                MessageBox.Show("Please Select Database Source.")
                ButtonSource.Focus()
                Exit Sub
            End If
            If TextBoxDestination.Text = "" Then
                MessageBox.Show("Please Select Database Destination.")
                ButtonDestination.Focus()
                Exit Sub
            End If
            If TextBoxFileName.Text = "" Then
                MessageBox.Show("Please Enter File Name.")
                TextBoxFileName.Focus()
                Exit Sub
            End If

            Dim ext As String
            ext = TextBoxSource.Text.Substring(TextBoxSource.Text.IndexOf(".") + 1)

            File.Copy(TextBoxSource.Text, TextBoxDestination.Text & "\" & TextBoxFileName.Text & "." & ext)

            MessageBox.Show("Successfully Backup Database.")
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Sub




I hope this will help-full for you..........


这篇关于使用vb.net备份访问数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆