vb sql数据库备份和恢复
我刚接触sql数据库备份和恢复,我从网上拷了一份代码下来,可是运行错误,各位高手帮看一下,谢谢!!!DimitmXAsListItem'定义一个ListItem对象Dim...
我刚接触sql数据库备份和恢复,我从网上拷了一份代码下来,可是运行错误,各位高手帮看一下,谢谢!!!
Dim itmX As ListItem '定义一个ListItem对象
Dim key, list, sql As String '定义字符串变量
Private Sub Form_Load()
Option1.Value = True '设置Option1的值为真
Dir1_Change
End Sub
Private Sub Dir1_Change()
File1.Path = Dir1.Path
'添加数据备份卡到列表中
ListView1.ListItems.Clear
If File1.ListCount <> 0 Then
a = 0 '给变量a设置初值
Do While File1.ListIndex < File1.ListCount - 1
File1.ListIndex = a '赋值给变量a
key = File1.FileName
Set itmX = ListView1.ListItems.Add(, , key, 1)
a = a + 1
Loop
End If
File1_Click
End Sub
Private Sub Drive1_Change()
Dir1.Path = Drive1.Drive
End Sub
Private Sub File1_Click()
Label1.Caption = Dir1.Path & "\" & File1.FileName '获得路径
End Sub
Private Sub ListView1_Click()
Label1.Caption = Dir1.Path & "\" & ListView1.SelectedItem '获得路径
End Sub
Private Sub CmdBackup_Click()
Dim S As String
Dim MesText As String
Dim sql As String
If Option1.Value = True Then
'备份数据库
S = Dir1.Path & "\" & Date & ".BAK"
If Label1.Caption = S Then
MsgBox "数据备份卡已存在!", , "提示窗口"
Else
'备份SQL Server数据库
sql = "backup DATABASE ChineseMedicine TO disk='" & S & "'"
Cnn.Execute sql
Cnn.Close
MsgBox "数据库备份成功!", , "提示窗口"
key = Date & ".BAK"
Set itmX = ListView1.ListItems.Add(, , key, 1)
End If
End If
If Option2.Value = True Then
'恢复指定路径下的数据库
If File1.ListCount <> 0 Then
If Label1.Caption <> "" Then
'数据恢复语句
sql = "RESTORE DATABASE ChineseMedicine from disk='" & Label1.Caption & "'"
Cnn.Execute sql '执行SQL语句
Cnn.Close
MsgBox "数据库恢复成功!", , "提示窗口"
Else
MsgBox "请选择要恢复的数据备份卡!", , "提示窗口"
End If
Else
MsgBox "请选择要恢复的数据备份卡!", , "提示窗口"
End If
End If
End Sub
能解决问题还可加分哦!!! 展开
Dim itmX As ListItem '定义一个ListItem对象
Dim key, list, sql As String '定义字符串变量
Private Sub Form_Load()
Option1.Value = True '设置Option1的值为真
Dir1_Change
End Sub
Private Sub Dir1_Change()
File1.Path = Dir1.Path
'添加数据备份卡到列表中
ListView1.ListItems.Clear
If File1.ListCount <> 0 Then
a = 0 '给变量a设置初值
Do While File1.ListIndex < File1.ListCount - 1
File1.ListIndex = a '赋值给变量a
key = File1.FileName
Set itmX = ListView1.ListItems.Add(, , key, 1)
a = a + 1
Loop
End If
File1_Click
End Sub
Private Sub Drive1_Change()
Dir1.Path = Drive1.Drive
End Sub
Private Sub File1_Click()
Label1.Caption = Dir1.Path & "\" & File1.FileName '获得路径
End Sub
Private Sub ListView1_Click()
Label1.Caption = Dir1.Path & "\" & ListView1.SelectedItem '获得路径
End Sub
Private Sub CmdBackup_Click()
Dim S As String
Dim MesText As String
Dim sql As String
If Option1.Value = True Then
'备份数据库
S = Dir1.Path & "\" & Date & ".BAK"
If Label1.Caption = S Then
MsgBox "数据备份卡已存在!", , "提示窗口"
Else
'备份SQL Server数据库
sql = "backup DATABASE ChineseMedicine TO disk='" & S & "'"
Cnn.Execute sql
Cnn.Close
MsgBox "数据库备份成功!", , "提示窗口"
key = Date & ".BAK"
Set itmX = ListView1.ListItems.Add(, , key, 1)
End If
End If
If Option2.Value = True Then
'恢复指定路径下的数据库
If File1.ListCount <> 0 Then
If Label1.Caption <> "" Then
'数据恢复语句
sql = "RESTORE DATABASE ChineseMedicine from disk='" & Label1.Caption & "'"
Cnn.Execute sql '执行SQL语句
Cnn.Close
MsgBox "数据库恢复成功!", , "提示窗口"
Else
MsgBox "请选择要恢复的数据备份卡!", , "提示窗口"
End If
Else
MsgBox "请选择要恢复的数据备份卡!", , "提示窗口"
End If
End If
End Sub
能解决问题还可加分哦!!! 展开
3个回答
今至电子科技有限公司
2024-08-23 广告
2024-08-23 广告
数据库备份是确保数据安全与业务连续性的关键环节。我们上海今至电子科技有限公司高度重视数据保护,定期执行全面的数据库备份策略。这包括使用先进工具和技术,对关键业务数据进行自动化备份,并存储在安全可靠的外部存储介质或云端。通过定期验证备份的完整...
点击进入详情页
本回答由今至电子科技有限公司提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询