Bonjour à tous,

Je tente de comprendre la commande ADODB.Recordset.Getrows sur un recordset alimenté par une requête SQL SERVER.

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
Private Sub cmdODBCStoreProc_Click()
 
    Dim vRows As Variant
    Dim sFirstName As String
    Dim iRows As Integer
 
    Call mfADODBCnxOpen
 
    Set goADODBRset = New ADODB.Recordset
 
    sFirstName = ""
    'sFirstName = """Le Nom"""
 
    With goADODBRset
        Set .ActiveConnection = goADODBCnx
        .Source = "EXEC [SalesLT].[spOrder]  " & sFirstName
        .LockType = adLockOptimistic
        .CursorType = adOpenKeyset
        .CursorLocation = adUseClient
        .Open
    End With
 
    iRows = goADODBRset.RecordCount
    MsgBox iRows
 
    'Set Forms("frmMain").Form.Controls("ctnrFrm2").Form.Recordset = goADODBRset
    Set Forms("frmMain").Form![ctnrFrm2].Form.Recordset = goADODBRset
 
    '********************************************************************************
    '
    '  Demonstration*of*the*Fields*Parameter*of*GetRows()
    '
    '********************************************************************************
 
    'Let's retrieve only the LastName Field in the rstEmployees Recordset
    vRows =  goADODBRset.GetRows(1,  , "LastName")
 
    'Let's retrieve only the 3rd Field ([Address]) in the rstEmployees Recordset
    varEmployees = rstEmployees.GetRows(rstEmployees.RecordCount, , 2)
 
    'Let's retrieve the [Address], [City], and [Region Fields by passing an Array of these Field Names as the Fields Parameter 
    vFieldNames = Array("CustomerID", "FirstName")
    vRows =  goADODBRset.GetRows(,  ,  avarFieldNames)
 
    goADODBRset.Close
    Set goADODBRset = Nothing
    Call mfADODBCnxClose
 
End Sub
 
 
Public Function mfADODBCnxOpen()
 
    Dim i  As Integer
    On Error GoTo Err_ 
 
    gsMsgErr = ""
 
    Set goADODBCnx = New ADODB.Connection
 
    With goADODBCnx
        .CommandTimeout = 15
        .Mode = adModeReadWrite
        .ConnectionString = ADODB_STRINGCNX
    End With
 
    goADODBCnx.Open    
Exit_:
        Exit Function
Err_:   
    gsMsgErr = Err.Number & Chr(13) & Err.Description
    GoTo Exit_
End Function
avec le code sur GetRows
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
 'Let's retrieve only the LastName Field in the rstEmployees Recordset
 vRows =  goADODBRset.GetRows(1,  , "LastName")
 
 'Let's retrieve only the 3rd Field ([Address]) in the rstEmployees Recordset
 varEmployees = rstEmployees.GetRows(rstEmployees.RecordCount, , 2)
 
 'Let's retrieve the [Address], [City], and [Region Fields by passing an Array of these Field Names as the Fields Parameter 
 vFieldNames = Array("CustomerID", "FirstName")
 vRows =  goADODBRset.GetRows(,  ,  avarFieldNames)
Quand une ligne de code GetRows est exécutée alors il y a l'erreur suivante
Erreur d'exécution '424' -Objet requis
Nom : GetRows.png
Affichages : 350
Taille : 41,6 Ko

Quelqu'un aurait une explication ?