Hello group, I’m back again for help. My brain is on fire, I’m turning into a second level super saiyan… I’m programming beyond my possibilities
I’m deleting records by year (and so far so good). Then, not happy, I wanted to count them (and so far so good). Not satisfied yet, I created a function to improve and speed up the code (and so far we are). But from these deleted records, I should also physically delete associated image files, each record has an associated image stored in an Image Path field, but when I go to delete it it doesn’t delete it… it deletes the record but not the associated image. …so in 1000 deletions, I will have 1000 image files of no one stored on the pc. HELP !
dim txtStart as string = "#" + DataDaEliminareDallatabella + "-01-01#"
dim txtEnd as string = "#" + format(val(DataDaEliminareDallatabella)+1, "0") + "-01-01#"
Var deleteSQL As String
Dim ConteggioRecordsDaEliminare as Integer = 0
// ** CANCELLAZIONE DATI OBSOLETI DALLE TABELLE DB IN BASE ALL'ANNO ** //
Try
If Not db.Connect Then Return -1
Var rs As RowSet = db.SelectSQL("SELECT COUNT(*) As ID FROM "+TabellaDaCuiEliminareRecords+" WHERE "+DenominazioneCampoDataNellaTabellaDB+" >= " +txtStart +" and "+DenominazioneCampoDataNellaTabellaDB+" <"+txtEnd)
If rs = Nil Or rs.AfterLastRow Then Return -1
ConteggioRecordsDaEliminare=rs.Column("ID").IntegerValue
Try
If MsgBox( "Eliminare da " + TabellaDaCuiEliminareRecords +" n°" + ConteggioRecordsDaEliminare.ToString + " records con anno " + DataDaEliminareDallatabella + " ? ", 36, "!! ATTENZIONE !!") = 6 Then
deleteSQL = "DELETE FROM "+TabellaDaCuiEliminareRecords+" WHERE "+DenominazioneCampoDataNellaTabellaDB+" >= " +txtStart +" and "+DenominazioneCampoDataNellaTabellaDB+" <"+txtEnd
Try
db.ExecuteSQL(deleteSQL)
'****************************************************************************************************************
'BLOCCO PER LA CANCELLAZIONE DEI FILE IMMAGINE LEGATI ALLA PATH DEL RECORD TROVATO LA CUI DATA SODDISFA I CRITERI
'****************************************************************************************************************
if TabellaDaCuiEliminareRecords="ArchiviazioneDisegniTecnici" then
rs = db.SelectSQL("SELECT * FROM ArchiviazioneDisegniTecnici WHERE "+DenominazioneCampoDataNellaTabellaDB+" >= " +txtStart +" and "+DenominazioneCampoDataNellaTabellaDB+" <"+txtEnd)
'''''**** BLOCCO CANCELLAZIONE FILE DA PATH ***********
Dim f As FolderItem
Dim dest1 as string
f = GetFolderItem("") 'Stringa vuota=Punta alla cartella dove risiede l'applicazione
f = f.Parent
While Not rs.AfterLastRow
'''''''''''' compongo la path per la cancellazione del file - BLOCCO CANCELLAZIONE FILE DA PATH
dest1=""
dest1=f.NativePath '=C:\Users\Federico\Desktop\TEST XOJO\MioMagazzino\
dest1=dest1+rs.Column("PathImmagine").StringValue
dest1=replaceall(dest1,"\\","\") 'rimpiazzo la doppia \\ con \ sola
Var f2 As New FolderItem(dest1)
If f2.Exists Then
Try
f2.Remove 'MessageBox("File removed!")
Catch error As IOException
MessageBox(error.Message)
End Try
else
messagebox("FILE non esiste")
End If
rs.MoveToNextRow
Wend
end if
'****************************************************************************************************************
'CHIUSURA - BLOCCO PER LA CANCELLAZIONE DEI FILE IMMAGINE LEGATI ALLA PATH DEL RECORD TROVATO LA CUI DATA SODDISFA I CRITERI
'****************************************************************************************************************
Catch error As DatabaseException
MessageBox(db.ErrorMessage)
End Try
else
'messagebox " Operazione annullata"
ConteggioRecordsDaEliminare=0
end if
return ConteggioRecordsDaEliminare
Catch err As DatabaseException
Return - err.ErrorNumber
End Try
Catch error As DatabaseException
MessageBox("Error: " + error.Message)
End Try
// ** END ** // // ** CANCELLAZIONE DATI OBSOLETI DALLE TABELLE DB IN BASE ALL'ANNO ** //
2 posts - 1 participant