vb判断数据库连接上否,如果连接失败,还没有判断就已经提示出错了,怎么处理啊
Set conn1 = New ADODB.Connection
conn1.ConnectionString = "driver={SQL Server};server=" & S(0) & ";uid=" & S(1) & ";pwd=" & S(2) & ";database=master"
conn1.Open
If conn1.State = 0 Then
还没有到if,由于连接本来就是失败的,到conn1.open时就提示报错了,这个怎么处理啊
[解决办法]
'使用on error goto错误跳转private sub command1_click()on error goto ErrHandle: Set conn1 = New ADODB.Connection conn1.ConnectionString = "driver={SQL Server};server=" & S(0) & ";uid=" & S(1) & ";pwd=" & S(2) & ";database=master" conn1.Open If conn1.State = 0 Then '... '... exit sub'错误处理ErrHandle: msgbox "操作失败,错误原因为:" & err.description,48,"提示" exit subend sub
[解决办法]