Recordset probléme

philo71 Messages postés 28 Date d'inscription vendredi 10 novembre 2000 Statut Membre Dernière intervention 10 mars 2008 - 16 avril 2005 à 16:58
philo71 Messages postés 28 Date d'inscription vendredi 10 novembre 2000 Statut Membre Dernière intervention 10 mars 2008 - 17 avril 2005 à 16:33
Bonjour,

je vous expose rapidement ma config, je fait une appli en vb 6 , avec sql serveur.
Les requétes sont effectuées a tranvers un adodc, mon recordset se remplit trés bien,
mais lorsque je complique le probléme , c'est que le recordset..movenext marche tres bien
ainsi que le recordset.movelast et le movefirst, mais du moment ou je fait un recordset . moveprevious j'ai une erreur et pourtant j'ai un "if" qui vérifie que je ne suis pas au début du recordset. , voici le message d'erreur du recordset.prévious : "erreur d'execution '3219'
opération is not allowed in this context", j'ai vérifié les propiétés de l'objet Adodc, si cela n'étais pas parramétrable.

PHILO

5 réponses

cs_Jack Messages postés 14006 Date d'inscription samedi 29 décembre 2001 Statut Modérateur Dernière intervention 28 août 2015 79
16 avril 2005 à 17:20
Salut
Voilà une belle erreur.
Et le code qui l'a généré, il est où ? Comment veux-tu qu'on te réponde ?
Comment as-tu fais ton test avant (le If) ?

Vala
Jack, MVP VB
NB : Je ne répondrai pas aux messages privés

Le savoir est la seule matière qui s'accroit quand on la partage. (Socrate)
0
Neo.balastik Messages postés 796 Date d'inscription jeudi 17 mai 2001 Statut Membre Dernière intervention 5 mai 2009 7
16 avril 2005 à 17:32
Salut ;O)

L'erreur pourrait venir du curseur utilisé.
Essaye de mettre la propriété CursorLocation de ton objet recordset sur adUserClient.

Parfois cela règle le problème car le serveur n'est peut-être pas capable de gérer certaines propriétés du curseur, donc plantage.

A essayer...

Guy
0
philo71 Messages postés 28 Date d'inscription vendredi 10 novembre 2000 Statut Membre Dernière intervention 10 mars 2008
16 avril 2005 à 18:54
re;
pour guy , mon cursorlocation est bien sur aduserclient

pour jack voila le code avec un commentaire sur l'erreur :

Option Explicit
' Auteur philo'

Public l_strconnectstring As String
Public l_strReq As String
Public l_rsRecord As New ADODB.Recordset
Public l_adoCommand As New ADODB.Command
Public p_strServeur As String
Public p_strBase As String
Public p_adoConnect As New ADODB.Connection








Private Sub Command1_Click()
'********** Conection a philo_es***********
'********** Conection a philo_es***********
Dim base As String
Dim l_strconnectstring As String
Dim l_strReq As String
Dim l_rsRecord As New ADODB.Recordset
Dim l_adoCommand As New ADODB.Command
List2.Clear
If p_adoConnect.State = adStateOpen Then
p_adoConnect.Close
End If
On Error GoTo erreur
base = "philo_es"
l_strconnectstring = "uid=;pwd=;driver={SQL Server}; server=" & p_strServeur & ";database=" & Trim(base) & ";dsn=''"
On Error GoTo erreur
With p_adoConnect
.ConnectionString = l_strconnectstring
.ConnectionTimeout = 0
.CommandTimeout = 0
.Open
End With
'MsgBox "connection à " & Trim(base) & " ouverte"
Label1.Caption = "Connecter a " & base


l_strReq "select name from sysobjects where xtype 'U' order by name "
l_adoCommand.ActiveConnection = p_adoConnect
l_adoCommand.CommandText = l_strReq
Set l_rsRecord = l_adoCommand.Execute
Do While Not l_rsRecord.EOF
List2.AddItem (l_rsRecord!Name)
l_rsRecord.MoveNext
Loop
Exit Sub
erreur:
MsgBox "Connection non établie"



End Sub


Private Sub Command2_Click()
'******** insertion **************
Dim l_strconnectstring As String
Dim l_strReq As String
Dim l_rsRecord As New ADODB.Recordset
Dim l_adoCommand As New ADODB.Command



Dim num As Integer
Dim nom As String
Dim prenom As String
Dim adr As String
Dim tel As Integer


num = Val(Trim(Text1.Text))
nom = Trim(Text2.Text)
prenom = Trim(Text3.Text)
adr = Trim(Text4.Text)
tel = Val(Trim(Text5.Text))


'l_strReq = "insert into table_client values (1, 'rego','victor','macon',0678626640)"
'l_strReq = "insert into table_client values (num , nom ,prenom ,adr ,tel )"
l_strReq = "insert into table_client values ("
l_strReq = l_strReq + "'" + nom + "','" + prenom + "','" + adr + "'," + Str(tel) + ")"
l_adoCommand.ActiveConnection = p_adoConnect
l_adoCommand.CommandText = l_strReq
Set l_rsRecord = l_adoCommand.Execute



End Sub


Function supprimeEnreg()
Dim l_strSql As String
Dim l_adoCommand As New ADODB.Command
On Error GoTo erreur
' modifier le nom de la table de l'exemple ainsi que la clause where
l_strSql = "delete from table_client where nom_client='rego'"
l_adoCommand.ActiveConnection = p_adoConnect
l_adoCommand.CommandText = l_strSql
l_adoCommand.CommandType = adCmdText
l_adoCommand.Execute
Exit Function
erreur:
MsgBox Err.Description, vbCritical

End Function








Private Sub Command5_Click()
'******** Suprimer **********


Call supprimeEnreg


End Sub


Private Sub Command6_Click()
'******* affichage des champs Select * from **********
Dim c As Integer
Dim r As Integer





Dim num As Integer
Dim nom As String
Dim prenom As String
Dim adr As String
Dim tel As Integer


'********* requete select avec choix *****************
If Trim(Text1.Text) = "" Then
l_strReq = "select * from table_client"
Else If Combo1.Text "" Then l_strReq "select * from table_client" If Combo1.Text "Numéro" Then l_strReq "select * from table_client where num_client=" + Trim(Text1.Text) If Combo1.Text "Nom" Then l_strReq "select * from table_client where nom_client like '" + Trim(Text1.Text) + "%" + "'" If Combo1.Text "Prénom" Then l_strReq "select * from table_client where prenom_client like '" + Trim(Text1.Text) + "%'"


End If








'l_strReq = "select * from table_client"
'l_strReq = "select nom_client from table_client"


l_adoCommand.ActiveConnection = p_adoConnect
l_adoCommand.CommandText = l_strReq
Set l_rsRecord = l_adoCommand.Execute
Call ini_MfGrid





c = 0
r = 1
Do While Not l_rsRecord.EOF
mfGrid.Col = c
mfGrid.Row = r
mfGrid.Text = l_rsRecord.Fields("num_client")
mfGrid.CellAlignment = flexAlignCenterCenter
c = c + 1
mfGrid.Col = c
mfGrid.Row = r
mfGrid.Text = l_rsRecord.Fields("nom_client")
mfGrid.CellAlignment = flexAlignLeftCenter
c = c + 1

mfGrid.Col = c
mfGrid.Row = r
mfGrid.Text = l_rsRecord.Fields("prenom_client")
mfGrid.CellAlignment = flexAlignLeftCenter
c = c + 1
mfGrid.Col = c
mfGrid.Row = r
mfGrid.Text = l_rsRecord.Fields("adr_client")
mfGrid.CellAlignment = flexAlignLeftCenter
c = c + 1
mfGrid.Col = c
mfGrid.Row = r
mfGrid.Text = l_rsRecord.Fields("tel_client")
mfGrid.CellAlignment = flexAlignLeftCenter

c = 0
r = r + 1



l_rsRecord.MoveNext
Loop


l_rsRecord.MoveFirst
Text6.Text = l_rsRecord.Fields("num_client")
Text7.Text = l_rsRecord.Fields("nom_client")
Text8.Text = l_rsRecord.Fields("prenom_client")
Text9.Text = l_rsRecord.Fields("adr_client")
Text10.Text = l_rsRecord.Fields("tel_client")



End Sub
Private Sub Command4_Click()
'*** champs précédent ****
'** voila ou ca plante , ** voila ou ca plante , ** voila ou ca plante , ** voila ou ca plante ,


If Not l_rsRecord.BOF Then
l_rsRecord.MovePrevious

Text6.Text = l_rsRecord.Fields("num_client")
Text7.Text = l_rsRecord.Fields("nom_client")
Text8.Text = l_rsRecord.Fields("prenom_client")
Text9.Text = l_rsRecord.Fields("adr_client")
Text10.Text = l_rsRecord.Fields("tel_client")
Else
MsgBox ("Début de table")
End If



End Sub
Private Sub Command7_Click()
'*** champs suivant ********
If Not l_rsRecord.EOF Then
l_rsRecord.MoveNext
Text6.Text = l_rsRecord.Fields("num_client")
Text7.Text = l_rsRecord.Fields("nom_client")
Text8.Text = l_rsRecord.Fields("prenom_client")
Text9.Text = l_rsRecord.Fields("adr_client")
Text10.Text = l_rsRecord.Fields("tel_client")
Else
MsgBox ("fin de table")
End If
End Sub


Private Sub Form_Load()
Combo1.Text = ""
Combo1.AddItem ""
Combo1.AddItem "Numéro"
Combo1.AddItem "Nom"
Combo1.AddItem "Prénom"



Label1.Caption = "non connecter"
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
Text4.Text = ""
Text5.Text = ""
Text6.Text = ""
Text7.Text = ""
Text8.Text = ""
Text9.Text = ""
Text10.Text = ""



End Sub



PHILO
0
cs_Jack Messages postés 14006 Date d'inscription samedi 29 décembre 2001 Statut Modérateur Dernière intervention 28 août 2015 79
17 avril 2005 à 03:27
A mon avis, ton erreur peut arriver si le recordset ne contient rien.
Essaye d'ajouter If l_rsrecord.RecordCount > 0 dans ta condition
Ou encore si le recordset n'a pas encore été défini --> Teste If Not l_rsrecord Is Nothing

Vala
Jack, MVP VB
NB : Je ne répondrai pas aux messages privés

Le savoir est la seule matière qui s'accroit quand on la partage. (Socrate)
0

Vous n’avez pas trouvé la réponse que vous recherchez ?

Posez votre question
philo71 Messages postés 28 Date d'inscription vendredi 10 novembre 2000 Statut Membre Dernière intervention 10 mars 2008
17 avril 2005 à 16:33
bonjour,
J'ai rajouté la condition "If l_rsrecord.RecordCount > 0 "

apparament le recordsetcount n'est pas plus grand que 0.
cela n'explique pas que le movenext marche tres bien.
quel est la suite faut t'il recharger le recorset ??
j'ai du mal a voir la suite !
PHILO
0
Rejoignez-nous