关于vb查询SQL server2000中表是否存在的问题
直接贴代码
Dim cn As New ADODB.ConnectionDim rs As New ADODB.RecordsetDim str As StringDim cn1 As New ADODB.ConnectionDim cmd As New ADODB.CommandDim rs1 As New ADODB.Recordsetcn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=false;Data Source=" & Trim(txtXLS.Text) & ";Extended Properties='Excel 8.0;HDR=Yes'"cn.Openrs.Open "select * from [" & Trim(cmbSheet.Text) & "$]", cn, adOpenKeyset, adLockOptimisticstr = "Driver={SQL Server};Server=" & Trim(txtServerName) & ";DataBase=" & Trim(txtDatabaseName) & ";UID=" & Trim(txtUsername) & ";PWD=" & Trim(txtPassword) & ";"cn1.Open str'On Error GoTo FindTableDim TableStr As StringTableStr = Trim(txtDatabaseName) & ".Owner." & Trim(txtTableName)Dim aSQL As StringaSQL = "select count(*) from sysobjects where id = object_id('" & Trim(TableStr) & "')"If cn1.Execute(aSQL) = 0 Then MsgBox "1"