Effacer des records

cs_Charlie Messages postés 110 Date d'inscription jeudi 9 mai 2002 Statut Membre Dernière intervention 11 mars 2010 - 27 juin 2002 à 15:22
cs_Charlie Messages postés 110 Date d'inscription jeudi 9 mai 2002 Statut Membre Dernière intervention 11 mars 2010 - 28 juin 2002 à 14:42
Allo...

Je travaille avec un recordset en ADO. Ce que je veux faire c'est effacer toute les lignes contenants un certain nom. Ainsi, je fais un find, avec le nom que je veux enlever pour ensuite faire delete. Mais a toute les fois, le delete plante... Il me dit que trop d'informations seraient changées par ce changement ou quelque chose du genre....

Il doit bien y avoir un moyen d'effacer, en boucle, une cinquantaine de record dans un recordset!

Merci

4 réponses

PatWolver Messages postés 12 Date d'inscription jeudi 23 mai 2002 Statut Membre Dernière intervention 2 décembre 2003
27 juin 2002 à 18:01
Salut,

Il te suffit d'exécuter une requete du style

DELETE NomDeTaTable
WHERE NomDuChamps Condition

exemple :
DELETE Clients
WHERE Nom LIKE 'Z%'

efface tous les clients dont le nom commence par Z

Ainsi tu n'as pas de boucle à faire.
Gain de temps important.

Si bleme écris moi
0
cs_Charlie Messages postés 110 Date d'inscription jeudi 9 mai 2002 Statut Membre Dernière intervention 11 mars 2010 1
27 juin 2002 à 19:00
Allo...

J'ai jamais fais de requetes avant alors, je ne sais pas quoi faire avec l'exemple que tu m'as donné!

Merci!
0
PatWolver Messages postés 12 Date d'inscription jeudi 23 mai 2002 Statut Membre Dernière intervention 2 décembre 2003
28 juin 2002 à 10:45
Salut,

Donne moi, si tu es d'accord, un exemple de ton code dans lequel tu accèdes à tes données, ainsi je pourrais plus facilement t'expliquer comment faire.
0
cs_Charlie Messages postés 110 Date d'inscription jeudi 9 mai 2002 Statut Membre Dernière intervention 11 mars 2010 1
28 juin 2002 à 14:42
Pas de problème... Comme c'est mon programme VB qui crée ses propre tables... tu vas avoir la forme complete de ma base de données...

Ce que je veux faire c'est effacer, dans la table "Data", les enregistrements dont la colonne "Name" = image.tif par exemple...

Je t'ai mis les 3 principales fonctions ainsi, tu devrais avoir tout ce qui te faut.

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 AddData(Value As clsData, Class As Integer)
On Error GoTo Annulation
rsData.AddNew
rsData.Fields("Indice") = Value.pNb

rsData.Fields("Name") = GetValue(rsImages!Name)
rsData.Fields("Class") = Class
rsData.Fields("Wall Area") = Value.pWallArea
rsData.Fields("Lumen Area") = Value.pLumenArea
rsData.Fields("Fibre Per") = Value.pFibrePer
rsData.Fields("Lumen Per") = Value.pLumenPer
rsData.Fields("CenterLine") = Value.pCenterLinePer
rsData.Fields("Fibre Width") = Value.pFibreWidth
rsData.Fields("Fibre Thick") = Value.pFibreThickness
rsData.Fields("Max Diam") = Value.pMaxDiameter
rsData.Fields("Min Diam") = Value.pMinDiameter
rsData.Fields("Mean Diam") = Value.pMeanDiameter
rsData.Fields("Aspect Ratio") = Value.pAspect
rsData.Update
Exit Function

Annulation:

MsgBox "AddData Error! " & error, vbExclamation, "ERROR"
IpAppCloseAll

End Function

Merci!!!!!!1
0
Rejoignez-nous