首页上一页 1 下一页尾页 1 条记录 1/1页
如何备份数据库?
发表在VB答疑区
2009-01-31
是否精华
是
否
版块置顶:
是
否
我在模仿贵司出版的《VB数据库系统开发案例精选》一书第7章344页的数据备份这一代码时,却提示:“无效的SQL语句”,请专家不吝赐教!,我的代码是(贵书源代码不曾改动,只是改成了连接我的数据库):
Dim StrCnn As New ADODB.Connection '定义连接
Private Sub Command1_Click()
CommonDialog1.Filter = "备份文件(*.mdb)|*.mdb|文本文件(*.txt)|*.txt|ALL File(*.*)|*.*"
CommonDialog1.ShowSave
Text1.Text = CommonDialog1.FileName
End Sub
Private Sub Command2_Click()
Command2.Enabled = False
Me.MousePointer = 11
If Text1.Text = "" Then
MsgBox "请您选择数据库备份的路径!", 64, "提示信息"
Else
Dim connter As Integer
Dim sql, workarea(12) As String
ProgressBar1.Visible = True
ProgressBar1.Max = UBound(workarea)
ProgressBar1.Value = ProgressBar1.Min
For connter = LBound(workarea) To UBound(workarea)
workarea(connter) = "initial value" & connter
ProgressBar1.Value = connter
StrCnn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\datasource\wgxxgl.mdb;Persist Security Info=False"
sql = "backup database wgxxgl TO disk='" & Text1.Text & "'"
StrCnn.Execute (sql) '执行SQL语句
StrCnn.Close
Next connter
ProgressBar1.Value = ProgressBar1.Min
MsgBox "数据库备份成功!!", 64, "提示信息"
Command2.Enabled = True
Me.MousePointer = 0
End If
End Sub
Dim StrCnn As New ADODB.Connection '定义连接
Private Sub Command1_Click()
CommonDialog1.Filter = "备份文件(*.mdb)|*.mdb|文本文件(*.txt)|*.txt|ALL File(*.*)|*.*"
CommonDialog1.ShowSave
Text1.Text = CommonDialog1.FileName
End Sub
Private Sub Command2_Click()
Command2.Enabled = False
Me.MousePointer = 11
If Text1.Text = "" Then
MsgBox "请您选择数据库备份的路径!", 64, "提示信息"
Else
Dim connter As Integer
Dim sql, workarea(12) As String
ProgressBar1.Visible = True
ProgressBar1.Max = UBound(workarea)
ProgressBar1.Value = ProgressBar1.Min
For connter = LBound(workarea) To UBound(workarea)
workarea(connter) = "initial value" & connter
ProgressBar1.Value = connter
StrCnn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\datasource\wgxxgl.mdb;Persist Security Info=False"
sql = "backup database wgxxgl TO disk='" & Text1.Text & "'"
StrCnn.Execute (sql) '执行SQL语句
StrCnn.Close
Next connter
ProgressBar1.Value = ProgressBar1.Min
MsgBox "数据库备份成功!!", 64, "提示信息"
Command2.Enabled = True
Me.MousePointer = 0
End If
End Sub