ADODB Recordset count -1, Sql Servre CE?
Bonjour,
Impossible de récupérer un recordset contenant des enregistrements...
J'ai lu le FAQ, essayé un bon nombre de code... Mais là je tourne en rond.
Premier code....
Code:
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
|
' Déclaration des variables
Dim oConnexion As New ADODB.Connection
Dim oRst As New ADODB.Recordset
Dim sSQL As String
Dim SourceDb As String
SourceDb = ThisWorkbook.Path & "\Bases\MyDatabase.sdf"
With oConnexion
.Provider = "Microsoft.SQLSERVER.CE.OLEDB.3.5"
.ConnectionString = "Data Source=" & SourceDb & ";"
End With
' Ouvrir la connexion
oConnexion.Open
' Exécution de la requête
sSQL = "SELECT * FROM TblRepertoire"
oRst.Open sSQL, oConnexion , , , adCmdText
' Renvoyer le recordset
MsgBox (oRst.RecordCount)
'Fermer les objets
oConnexion.Close |
Le second
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
|
Dim oConnexion As ADODB.Connection
Dim oRst As ADODB.Recordset
Set oConnexion = New ADODB.Connection
Dim oCmd As New ADODB.Command
Set oRst = New ADODB.Recordset
With oConnexion
.Provider = "Microsoft.SQLSERVER.CE.OLEDB.3.5"
.ConnectionString = ThisWorkbook.Path & "\Bases\MyDatabase.sdf"
.Open
End With
With oCmd
.ActiveConnection = oConnexion
.CommandText = "SELECT * FROM TblRepertoire"
'.CommandText = "INSERT INTO TblRepertoire (Nom) VALUES('KKK')"
End With
Set oRst = oCmd.Execute
MsgBox oRst.RecordCount |
Recordcount renvoi toujours -1....
Pourtant dans le second code, la requête est bien exécutée....
Merci pour le coup de main
Gdal