Effacer un enregistrement

cs_Charlie Messages postés 110 Date d'inscription jeudi 9 mai 2002 Statut Membre Dernière intervention 11 mars 2010 - 3 juil. 2002 à 15:31
cs_Charlie Messages postés 110 Date d'inscription jeudi 9 mai 2002 Statut Membre Dernière intervention 11 mars 2010 - 10 nov. 2002 à 17:07
Allo... j'essaie d'effacer, dans ma table Data, tous les enregistrements dont le champ Name correspond a un certain nom.

A toute les fois qu'il arrive pour effacer le premier, il me sort ce message d'erreur:

Key column information is insufficient or incorrect. Too many rows were affected by update.

Voici mon code...

rsdata est du type Adodb.recordset

Public Function DeleteImageData(Image As String)

If rsData.RecordCount > 0 Then
rsData.MoveFirst

Do While rsData.EOF = False

If Trim(GetValue(rsData!name)) = Image then
rsData.Delete adAffectCurrent
rsData.Update
End If
rsData.MoveNext
Loop

End If
rsData.Update

End Function

Merci!!!!

5 réponses

PatriceVB Messages postés 562 Date d'inscription dimanche 16 décembre 2001 Statut Modérateur Dernière intervention 26 décembre 2007
3 juil. 2002 à 17:47
crée un objet command avec une requete sql qui permet d'effacer les occurences que tu auras sélectionné selon un critère.
@+
0
cs_Charlie Messages postés 110 Date d'inscription jeudi 9 mai 2002 Statut Membre Dernière intervention 11 mars 2010 1
3 juil. 2002 à 18:32
peut-être bien... mais comment on fait ca...

Ce que je veux faire c'est d'effacer, dans mon recordset rsdata (qui corrspond a ma table data), les enregistrements qui ont le champ name= qqch

Je t'envois le bout de mon code qui ouvre ma base de donnée et qui l'active!

L'ordre d'exécution des fonctions est la suivante...

Si je crée une DB... createDB, activeDB,delete (qui marche pas), closeDB

Si j'ouvre une table existante... opendb,activedb,delete(...) closeDB

Option Explicit

Private cat As New ADOX.Catalog
Private Tbl As New ADOX.Table
Private cmdado As New ADODB.command
Private rsProject As New ADODB.Recordset
Private rsImages As New ADODB.Recordset
Private rsData As New ADODB.Recordset

Public Function CreateDB(link As String) As Boolean

On Error GoTo Annulation
cat.Create "provider=microsoft.jet.oledb.3.51;" & "Data source =" & link & ";"

With Tbl
.Name = "Project"
.Columns.append "Log Nb", adChar, 50
.Columns.append "Sample Nb", adChar, 50
.Columns.append "Name", adChar, 50
.Columns.append "Path", adChar, 255
.Columns.append "Images From", adChar, 255

End With

cat.Tables.append Tbl
Set Tbl = Nothing

With Tbl
.Name = "Images"
.Columns.append "CalculDone", adBoolean
.Columns.append "BorderDone", adBoolean
.Columns.append "SplitDone", adBoolean
.Columns.append "ClassDone", adBoolean
.Columns.append "Name", adChar, 50
.Columns.append "Dimension", adChar, 50
End With
cat.Tables.append Tbl
Set Tbl = Nothing

With Tbl
.Name = "Data"

.Columns.append "Name", adChar, 50
.Columns.append "Indice", adInteger
.Columns.append "Class", adInteger
.Columns.append "Wall Area", adDouble
.Columns.append "Lumen Area", adDouble
.Columns.append "Fibre Per", adDouble
.Columns.append "Lumen Per", adDouble
.Columns.append "CenterLine", adDouble
.Columns.append "Fibre Width", adDouble
.Columns.append "Fibre Thick", adDouble
.Columns.append "Max Diam", adDouble
.Columns.append "Min Diam", adDouble
.Columns.append "Mean Diam", adDouble
.Columns.append "Aspect Ratio", adDouble
End With
cat.Tables.append Tbl
Set Tbl = Nothing

ActiveDB
CreateDB = True

Exit Function
Annulation:
CreateDB = False
MsgBox "CreateDB Error! " & error, vbExclamation, "ERROR"
CloseDB

End Function

Private Function ActiveDB()

On Error GoTo Annulation

cmdado.ActiveConnection = cat.ActiveConnection
cmdado.CommandText = " select * from Project"

rsProject.CursorLocation = adUseClient
rsProject.CursorType = adOpenDynamic
rsProject.LockType = adLockOptimistic
rsProject.Open cmdado

cmdado.CommandText = " select * from Images"
rsImages.CursorLocation = adUseClient
rsImages.CursorType = adOpenDynamic
rsImages.LockType = adLockOptimistic
rsImages.Open cmdado

cmdado.CommandText = " select * from Data " ' order by name indice asc"
rsData.CursorLocation = adUseClient
rsData.CursorType = adOpenDynamic
rsData.LockType = adLockOptimistic
rsData.Open cmdado

ActiveDB = True
Exit Function

Annulation:
ActiveDB = False
MsgBox "ActiveDB Error! " & error, vbExclamation, "ERROR"

CloseDB

End Function

Public Function OpenDB(link As String) As Boolean

On Error GoTo Annulation
cat.ActiveConnection = "provider=microsoft.jet.oledb.3.51;" & "Data source =" & link & ";"

If ActiveDB = True Then
OpenDB = True
Else
OpenDB = False
End If
Exit Function
Annulation:
OpenDB = False

MsgBox "OpenDB Error! " & error, vbExclamation, "ERROR"

CloseDB

End Function

Public Function CloseDB()
On Error GoTo Annulation

Set cat = Nothing
Set Tbl = Nothing
Set cmdado = Nothing
Set rsProject = Nothing
Set rsImages = Nothing
Set rsData = Nothing

Exit Function
Annulation:

MsgBox "CloseDB Error! " & error, vbExclamation, "ERROR"

End Function
0
cs_Charlie Messages postés 110 Date d'inscription jeudi 9 mai 2002 Statut Membre Dernière intervention 11 mars 2010 1
3 juil. 2002 à 22:41
Allo...

J'ai finalement trouvé comment faire. Seul petit probleme, comment on fait pour updater le recordset apres le DELETE.. le seul moyen que j'ai trouvé est de fermé moin recordset et de le réouvrir mais il doit bien y avoir un genre d'update???
0
ova13 Messages postés 1 Date d'inscription dimanche 10 novembre 2002 Statut Membre Dernière intervention 10 novembre 2002
10 nov. 2002 à 16:38
Ben tu mets tout simplement la methode .update sur ton recordset !

Moi je dis "CONICHON AHHHH !!"
0

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

Posez votre question
cs_Charlie Messages postés 110 Date d'inscription jeudi 9 mai 2002 Statut Membre Dernière intervention 11 mars 2010 1
10 nov. 2002 à 17:07
Et moi je te réponds... essaie le donc avant de dire n'importe quoi sur des messages vieux de 4 mois!!!

.update ne fonctionne pas... Je l'avais essayé dans le temps!

Moi je dis "P'tit Joe connaissant qui ne sais pas tout!!"
0
Rejoignez-nous