Private Sub Command1_Click() Dim gDBConnect As New ADODB.Connection On Error GoTo acd gDBConnect.ConnectionString = "Provider=sqloledb;Data Source=服务器IP;Initial Catalog=" & "csdb" & ";User Id=sa;Password=1234" gDBConnect.Open Exit Sub acd: '连接失败,在这里处理把数据保存为excelEnd Sub
Dim gDBConnect As New ADODB.Connection
On Error GoTo acd
gDBConnect.ConnectionString = "Provider=sqloledb;Data Source=服务器IP;Initial Catalog=" & "csdb" & ";User Id=sa;Password=1234"
gDBConnect.Open
Exit Sub
acd:
'连接失败,在这里处理把数据保存为excelEnd Sub