|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
代码如下,连接时报错。
另如想用InputBox动态用户名和密码该怎么做
先谢谢了
Public Sub 连接()
Dim cnn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim i As Long
Dim mydata As String, myTable As String
Dim str1, str2
str2 = InputBox(1, 2, 3)
mydata = "aa"
myTable = "bb"
Set cnn = New ADODB.Connection
With cnn
.ConnectionString = "Provider=SQLOLEDB.1;" _
& "User ID=多多;" _
& "Data Source=TDDL-SL;" _
& "PWD=123456" _
& ";DATABASE=" _
& "Initial Catalog=" & mydata
.Open
End With
Set rs = New ADODB.Recordset
rs.Open myTable, cnn, adOpenKeyset, adLockOptimistic
Cells.Clear
' With rs
' For i = 1 To .Fields.Count
' Cells(1, i).Value = .Fields(i - 1).Name
' Next
' Range("A2").CopyFromRecordset rs
' End With
rs.Close
cnn.Close
Set rs = Nothing
Set cnn = Nothing
End Sub |
|