Excel 2010 VBA Tutorial 91 - ADODB - SQL Parameters

preview_player
Показать описание
Рекомендации по теме
Комментарии
Автор

hi, great explanation. But how do you use it with multiple parameters. is it appended multiple times in cmd parameter or is it added multiple times into paraUserId object?

jonx
Автор


Anyways, here is my code. Can you spot anything wrong with it?

Sub loadEmployees()

Dim SQLstr As String
Dim rs As Object
Dim cmd As Object
Dim paramName As Object
Dim name As String
Set rs =
name = InputBox("Please advise Name")
Call connectDatabase
Set cmd = CreateObject("ADODB.Command")

With cmd
.ActiveConnection = DBCONT
.CommandText = SQLstr
End With


rs.Open cmd

For i = 1 To rs.RecordCount
With ThisWorkbook.Sheets("Sheet2")
.Cells(i, 1).Value = rs(0)
.Cells(i, 2).Value = rs(1)
.Cells(i, 3).Value = rs(2)
End With
rs.MoveNext
Next i

rs.Close
Set rs = Nothing
Call closeDatabase

End Sub

Clarkson