自己试一下吧,应该可以的
PRivate Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Dim lpass As Boolean
If MsgBox("请确认是否恢复,恢复时会把原来的数据删除,请告知每个使用用户,请确认没有其他用户在使用系统!!!", MsgBoxStyle.OKCancel + MsgBoxStyle.Critical + MsgBoxStyle.DefaultButton2, "警告") <> MsgBoxResult.OK Then
Exit Sub
End If
If txt_BakPath.Text = "" Then
MsgBox("恢复路径不能为空!")
Exit Sub
End If
Dim trans As SqlTransaction
Dim Mycn As New SqlConnection() '("User ID=sa;password=;Initial Catalog=master;Data Source=LOCALHOST;")
Dim mycn1 As New SqlConnection()
Mycn = cn.GetCN
If Mycn.State = ConnectionState.Closed Then
Mycn.Open()
End If
' cn.GetCN.Close()
' mycn1.Close()
Dim sqlBP As New SqlCommand()
Dim sqlInset As New SqlCommand()
Try
With sqlBP
.Connection = Mycn
.CommandType = CommandType.Text
dsRestore.Clear()
daRestore = New SqlDataAdapter("select * from t9_004 where status=1 order by bakdate desc", cn.GetCN)
daRestore.Fill(dsRestore, "t9_004")
DG1.DataSource = dsRestore
DG1.DataMember = "t9_004"
Catch e1 As SqlException
MsgBox("失败!" & Err.Description)
If lpass = True Then
trans.Rollback()
End If
End Try