我用vb执行多条sql语句,若其中某条查询报错,我如何获得这个错误信息?
declare@sql1nvarchar(4000)declare@sql2nvarchar(4000)set@sql1='insertintoT1(C1,C2)sele...
declare @sql1 nvarchar(4000)
declare @sql2 nvarchar(4000)
set @sql1=' insert into T1(C1,C2)
select V1,V2
from T2 '
set @sql2=' insert into T3(C1,C2)
select V1,V2
from T4 '
exec (@sql1)
exec (@sql2)
这是我要在vb中执行的语句,若第2个exec 执行出错,vb的连接对象 它不能提示错误。 展开
declare @sql2 nvarchar(4000)
set @sql1=' insert into T1(C1,C2)
select V1,V2
from T2 '
set @sql2=' insert into T3(C1,C2)
select V1,V2
from T4 '
exec (@sql1)
exec (@sql2)
这是我要在vb中执行的语句,若第2个exec 执行出错,vb的连接对象 它不能提示错误。 展开
1个回答
2010-09-28
展开全部
On Error goto ...
Private Sub TestErr(ByVal Var As Integer)'这只是例子
On Error GoTo ErrorHandle
Dim strError As String
'TempValue = Var / 0
'...
'这边写你要测试的代码。
'...
Exit Sub
ErrorHandle:
strError = strError & "ErrorDescription: " & Err.Description & vbCrLf
strError = strError & "ErrorNumber: " & Err.Number & vbCrLf
strError = strError & "ErrorSource: " & Err.Source
MsgBox strError, , "ErrorInformation"
Resume Next
End Sub
Private Sub TestErr(ByVal Var As Integer)'这只是例子
On Error GoTo ErrorHandle
Dim strError As String
'TempValue = Var / 0
'...
'这边写你要测试的代码。
'...
Exit Sub
ErrorHandle:
strError = strError & "ErrorDescription: " & Err.Description & vbCrLf
strError = strError & "ErrorNumber: " & Err.Number & vbCrLf
strError = strError & "ErrorSource: " & Err.Source
MsgBox strError, , "ErrorInformation"
Resume Next
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询