任何人都可以帮助保存目录 [英] can anyone help with save directory

查看:98
本文介绍了任何人都可以帮助保存目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



大家好

我有这个代码它工作正常但我想选择保存备份文件的位置




Hi guys
I have this code it works fine but I want to choose where to save the backup file

Private Sub frmMain_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
       Dim reply As DialogResult = MessageBox.Show("Δημιουργία αντιγράφου ασφαλείας ?", "Ερώτημα", _
             MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1)
       If reply = DialogResult.Yes Then
           sqlcon.ConnectionString = "Server=......\SQLEXPRESS;database=" + dbname + ";uid=sa;pwd=........;"
           Dim destdir As String = "G:\RDMSbackup"
           If Not System.IO.Directory.Exists(destdir) Then
               System.IO.Directory.CreateDirectory("G:\RDMSbackup")
           End If
           Try
               sqlcon.ConnectionString = "Server=.....\SQLEXPRESS;database=" + dbname + ";uid=sa;pwd=.....;"
               sqlcon.Open()
               sqlcmd = New SqlCommand("backup database  " + dbname + " to disk='" + destdir + "\" + DateTime.Now.ToString("ddMMyyyy_HHmmss") + ".Bak'", sqlcon)
               sqlcmd.ExecuteNonQuery()
               sqlcon.Close()
               'MessageBox.Show("Το Αντίγραφο της Βάσης Δεδομένων Δημιουργήθηκε")
               MsgBox("Το Αντίγραφο της Βάσης Δεδομένων Δημιουργήθηκε!", MsgBoxStyle.Information, "Πληροφορία")
           Catch ex As Exception
               'MessageBox.Show("Αποτυχία Δημιουργίας Αντιγράφου Ασφαλείας!")
               MsgBox("Αποτυχία Δημιουργίας Αντιγράφου Ασφαλείας!", MsgBoxStyle.Information, "Πληροφορία")
           End Try
       Else
           sqlSTR = "UPDATE Audit_Log SET LOGOUT ='" & TimeOfDay & "' WHERE User_ID =" & xUser_ID & " AND LOG_ID=" & LOGID
           ExecuteSQLQuery(sqlSTR)
       End If
   End Sub





请帮助



Please help

推荐答案

这应该有帮助,



http://www.java2s.com/Code/VBAPI/System.Windows.Forms/SaveFileDialogFilter.htm [ ^ ]



http://www.dotnetheaven.com/article/ savefiledialog-component-in-vb.net [ ^ ]
This should help,

http://www.java2s.com/Code/VBAPI/System.Windows.Forms/SaveFileDialogFilter.htm[^]

http://www.dotnetheaven.com/article/savefiledialog-component-in-vb.net[^]


嗯....



hmm....

Private Sub frmMain_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
       Dim reply As DialogResult = MessageBox.Show("Δημιουργία αντιγράφου ασφαλείας ?", "Ερώτημα", _
             MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1)
       If reply = DialogResult.Yes Then
           sqlcon.ConnectionString = "Server=......\SQLEXPRESS;database=" + dbname + ";uid=sa;pwd=........;"

           Dim destdir As String
           Dim dlg As SaveFileDialog
           dlg = New SaveFileDialog
           
           If dlg.ShowDialog = Windows.Forms.DialogResult.OK Then
               destdir = (CType(dlg.FileName, String))
           Else
               Exit Sub
           End If
         
           'If Not System.IO.Directory.Exists(destdir) Then
           '    System.IO.Directory.CreateDirectory("G:\RDMSbackup")
           'End If
           Try
               sqlcon.ConnectionString = "Server=.....\SQLEXPRESS;database=" + dbname + ";uid=sa;pwd=.....;"
               sqlcon.Open()
               sqlcmd = New SqlCommand("backup database  " + dbname + " to disk='" + destdir + "\" + DateTime.Now.ToString("ddMMyyyy_HHmmss") + ".Bak'", sqlcon)
               sqlcmd.ExecuteNonQuery()
               sqlcon.Close()
               'MessageBox.Show("Το Αντίγραφο της Βάσης Δεδομένων Δημιουργήθηκε")
               MsgBox("Το Αντίγραφο της Βάσης Δεδομένων Δημιουργήθηκε!", MsgBoxStyle.Information, "Πληροφορία")
           Catch ex As Exception
               'MessageBox.Show("Αποτυχία Δημιουργίας Αντιγράφου Ασφαλείας!")
               MsgBox("Αποτυχία Δημιουργίας Αντιγράφου Ασφαλείας!", MsgBoxStyle.Information, "Πληροφορία")
           End Try
       Else
           sqlSTR = "UPDATE Audit_Log SET LOGOUT ='" & TimeOfDay & "' WHERE User_ID =" & xUser_ID & " AND LOG_ID=" & LOGID
           ExecuteSQLQuery(sqlSTR)
       End If
   End Sub


这篇关于任何人都可以帮助保存目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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