📄 frmbackup.vb
字号:
Imports System.Data
Imports System.Data.sqlclient
Public Class frmbackup
Inherits System.Windows.Forms.Form
#Region " Windows 窗体设计器生成的代码 "
Public Sub New()
MyBase.New()
'该调用是 Windows 窗体设计器所必需的。
InitializeComponent()
'在 InitializeComponent() 调用之后添加任何初始化
End Sub
'窗体重写 dispose 以清理组件列表。
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Windows 窗体设计器所必需的
Private components As System.ComponentModel.IContainer
'注意: 以下过程是 Windows 窗体设计器所必需的
'可以使用 Windows 窗体设计器修改此过程。
'不要使用代码编辑器修改它。
Friend WithEvents tbpath As System.Windows.Forms.TextBox
Friend WithEvents Label1 As System.Windows.Forms.Label
Friend WithEvents bnbegin As System.Windows.Forms.Button
Friend WithEvents bncancel As System.Windows.Forms.Button
Friend WithEvents bnpath As System.Windows.Forms.Button
Friend WithEvents dlgpath As System.Windows.Forms.SaveFileDialog
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(frmbackup))
Me.tbpath = New System.Windows.Forms.TextBox
Me.bnpath = New System.Windows.Forms.Button
Me.Label1 = New System.Windows.Forms.Label
Me.bnbegin = New System.Windows.Forms.Button
Me.bncancel = New System.Windows.Forms.Button
Me.dlgpath = New System.Windows.Forms.SaveFileDialog
Me.SuspendLayout()
'
'tbpath
'
Me.tbpath.Location = New System.Drawing.Point(96, 40)
Me.tbpath.Name = "tbpath"
Me.tbpath.Size = New System.Drawing.Size(168, 21)
Me.tbpath.TabIndex = 0
Me.tbpath.Text = ""
'
'bnpath
'
Me.bnpath.Location = New System.Drawing.Point(280, 40)
Me.bnpath.Name = "bnpath"
Me.bnpath.TabIndex = 1
Me.bnpath.Text = "选择路径"
'
'Label1
'
Me.Label1.Location = New System.Drawing.Point(24, 40)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(72, 23)
Me.Label1.TabIndex = 2
Me.Label1.Text = "备份路径:"
Me.Label1.TextAlign = System.Drawing.ContentAlignment.MiddleLeft
'
'bnbegin
'
Me.bnbegin.Location = New System.Drawing.Point(56, 88)
Me.bnbegin.Name = "bnbegin"
Me.bnbegin.TabIndex = 3
Me.bnbegin.Text = "开始"
'
'bncancel
'
Me.bncancel.Location = New System.Drawing.Point(208, 88)
Me.bncancel.Name = "bncancel"
Me.bncancel.TabIndex = 4
Me.bncancel.Text = "取消"
'
'dlgpath
'
Me.dlgpath.Title = "把数据库备份到"
'
'frmbackup
'
Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
Me.ClientSize = New System.Drawing.Size(384, 165)
Me.Controls.Add(Me.bncancel)
Me.Controls.Add(Me.bnbegin)
Me.Controls.Add(Me.Label1)
Me.Controls.Add(Me.bnpath)
Me.Controls.Add(Me.tbpath)
Me.Icon = CType(resources.GetObject("$this.Icon"), System.Drawing.Icon)
Me.Name = "frmbackup"
Me.Text = "----------数据库备份"
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub bnpath_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bnpath.Click
dlgpath.ShowDialog()
tbpath.Text = dlgpath.FileName
End Sub
Private Sub bnbegin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bnbegin.Click
If tbpath.Text = "" Then
MessageBox.Show("请输入备份文件路径")
Exit Sub
End If
Dim filepath = tbpath.Text.Trim
'输入值完整并可用,插入记录到数据库
Dim strSource As String = "workstation id=郭洪博;packet size=4096;integrated security=SSPI;initial catalog=books;persist security info=False"
Dim strinsert As String = "backup database books to disk='" + filepath + "'"
Dim conn As New SqlConnection(strSource)
Try
conn.Open()
Dim cmd As New SqlCommand(strinsert, conn)
Dim ret As Integer = cmd.ExecuteNonQuery()
If ret <> 1 Then
MessageBox.Show("备份成功!")
Else
MessageBox.Show("备份失败")
End If
Catch ex As Exception
MessageBox.Show(ex.ToString)
End Try
conn.Close()
End Sub
Private Sub bncancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bncancel.Click
Me.Close()
End Sub
Private Sub frmbackup_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
End Class
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -