次のコードを使用して、SQLサーバーとの接続を開き、結果を配列に直接ドロップします。私の問題は、私は私の配列をredimする必要がある行数のエラーを取得することです。私が手にエラーを以下に示すライン上にあり、VBAの "行セットは後方にフェッチをサポートしていません" .cursertypeが調整されたエラー
が私は問題のように、カーソルの種類を提案する見つけることができるすべての答えを「行セットは後方フェッチをサポートしていません」と書かれ、私はこれを変更しました私の知る限り。ロングコードのための謝罪は、私はそれが最高のスタートを残すように感じた私は、これは、この質問の重複であることを信じていません
Function ConnectServer() As String()
'Working SQL Server connection
Dim conn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim sConnString As String
Dim strSqlQuery As String
Dim iCols As Long
' Create the connection string.
sConnString = "Provider=SQLOLEDB;Data Source=wait;" & _
"Initial Catalog=what;" & _
"User Id=foo;" & _
"Password=bar;"
' Create the Connection and Recordset objects.
Set conn = New ADODB.Connection
Set rs = New ADODB.Recordset
rs.CursorType = adOpenDynamic
rs.CursorLocation = adUseClient
conn.CommandTimeout = 50
' Open the connection and execute.
conn.Open sConnString
' Debug.Print strSqlQuery
Set rs = conn.Execute("SELECT DISTINCT a FROM b")
' Check we have data.
If Not rs.EOF Then
'*****************Problem here********************
rs.MoveLast
Debug.Print rs.RecordCount
'Read into array and cleanup...
End If
End Function
:。私はすでに組み込まれているので
Rowset does not support scrolling backward
私のコードへの答えと問題は依然として続きます。
すべてのレコードを配列に追加していますか? –
ええと、私は配列を赤字にするためにレコードを数える必要があります。次にそれらを追加します – User632716