ecranbleu27
Messages postés190Date d'inscriptionvendredi 4 juin 2004StatutMembreDernière intervention29 avril 2009
-
2 mars 2006 à 17:43
ecranbleu27
Messages postés190Date d'inscriptionvendredi 4 juin 2004StatutMembreDernière intervention29 avril 2009
-
3 mars 2006 à 05:17
bjr
j'ai un pb avec recordcount
voici mon code:
Dim x As Integer, Z As Integer
Dim y As String, W As String
Dim adoconnection As ADODB.Connection
Dim adorecordset As ADODB.Recordset
Dim CONNECTSTRING As String
Set adoconnection = New ADODB.Connection
Set adorecordset = New ADODB.Recordset
Dim resultat As String
Dim NOM2 As String
Randomize
CONNECTSTRING = "provider=microsoft.jet.oledb.4.0;" & "data source=c:\jeucalin\gages.mdb"
adoconnection.Open CONNECTSTRING '+le mot de passe
If truc "F" Then W "A"
If bidule "H" Then W "B"
Z = adorecordset.RecordCount
x = (Int(Rnd * Z)) 'Nb aléatoire
resultat = "select * from " & (W) & " where numéro=" & x
adorecordset.Open resultat, adoconnection, , , adCmdText
Text1 = adorecordset!gage
Je n'arrive pas à déterminer le Z pour qu'il me prenne un enregistrement alléatoire sur ma base.
Neow26
Messages postés50Date d'inscriptionmercredi 19 mars 2003StatutMembreDernière intervention12 mai 2007 2 mars 2006 à 19:25
Déjà dans ton extrait de code tu récupères ton recordcount avant d'ouvrir ton rs donc normal qu'il soit pas initialisé.
Ensuite, il faut faire attention aux options que tu utilises, si tu ouvre ton rs en adOpenForwardOnly, ton recordcount sera à 0 à l'ouverture alors qu'en adOpenStatic il sera bien initialisé. Par contre avec le adOpenStatic les performances sont moins bonnes.
La meilleur solution reste de faire une requete count en adOpenForwardOnly dans un souci de performances.
Ce qui te donnerai :
adorecordset.Open "select count(*) as Nb from " & (W), adoconnection, adOpenForwardOnly, adLockReadOnly
if not adorecordset.EOF then
Z = CInt(adorecordset("Nb"))
adorecordset.close
x = (Int(Rnd * Z)) 'Nb aléatoire
resultat = "select * from " & (W) & " where numéro=" & x
adorecordset.Open resultat, adoconnection, adOpenForwardOnly, adLockReadOnly
end if