salve,io ho una pagina asp degli articolo che hanno un giorno di scadenza,come posso fare per fari si che l'0oggeto "a" che scade oggi alla mezzanotte di oggi venga eliminato in automatico dal database?
grazie
salve,io ho una pagina asp degli articolo che hanno un giorno di scadenza,come posso fare per fari si che l'0oggeto "a" che scade oggi alla mezzanotte di oggi venga eliminato in automatico dal database?
grazie
soluzione possibile:
quando viene caricata la pagina di visualizzazione fai un controllo dei prodotti in scadenza: se data scadenza è < data odierna allora fai una query DELETE ...
Pesa più un litro d'acqua o uno d'olio...?
La prima persona al mondo a finire Splinter Cell uccidendo solo una persona. Già che c'ero l'ho fatto anche in Splinter Cell 2: solo 5 UCCISIONI
.*zerOKilled*.
se non vuoi cancellare veramente l'articolo, visualizzi solo quelli che non sono scaduti, con un'opportuna IF all'inizio della pagina di visualizzazione
Pesa più un litro d'acqua o uno d'olio...?
La prima persona al mondo a finire Splinter Cell uccidendo solo una persona. Già che c'ero l'ho fatto anche in Splinter Cell 2: solo 5 UCCISIONI
.*zerOKilled*.
grazie,mi potresti fare un esempio?(uno scipt)
non sono espertissimo...
'**************************************
' Name: GENERIC REMOVE OLD RECORDS FUNCT
' ION
' Description:Function to clear old reco
' rds from your database x number of days
' or older. Great for cleaning up database
' s.
' By: Anthony J. Biondo Jr
'
'
' Inputs:The function takes in the DSN C
' onnection string, table name, field wher
' e you hold your date, and how many days
' old the records should be before being d
' eleted. For example if you pass a 20 you
' will delete records 20 days or older. Yo
' u can this function in some sort of head
' er and call it within one of your applic
' ations whenever a user does a certain ta
' sk, for example: a user visits your home
' pages and you call the function like in
' the example below.
'
' Returns:The function treturns a positi
' ve 1 if the delete worked and a negative
' 1 if the delete failed.
'
'Assumes:None
'
'Side Effects:none known
'This code is copyrighted and has limite
' d warranties.
'Please see http://www.Planet-Source-Cod
' e.com/xq/ASP/txtCodeId.6694/lngWId.4/qx/
' vb/scripts/ShowCode.htm
'for details.
'**************************************
<%
' GENERIC REMOVE OLD RECORDS FUNCTION
' DATE: 06/04/2001
' AUTHOR: Anthony J. Biondo Jr. - antho
' nyb@inbridesburg.com - (http://www.chern
' oblechicken.com)
' DESCRIPTION: Function to clear old re
' cords from your database x number of day
' s or older. Great for cleaning up databa
' ses.
' INPUTS: The function takes in the DSN
' Connection string, table name, field whe
' re you hold your date, and how many days
' old the
' records should be before being delete
' d. For example if you pass a 20 you will
' delete records 20 days or older. You can
'
' include this function in some sort of
' header and call it within one of your ap
' plications whenever a user does a certai
' n
' task, for example: a user visits your
' home pages and you call the function lik
' e in the example below.
'
' INPUT EXAMPLES:
' myDSN = "DSN=bqueue"
' myDSN = "Driver={SQL Server}; Serve
' r=1.1.0.1; Database=mydb; Uid=user; Pwd=
' 123;
' table_name = "orders_received"
' date_field = "my_date"
' daysold = "30"
'
' OUTPUT: The function treturns a positi
' ve 1 if the delete worked and a negative
' 1 if the delete failed.
'
' REMARKS: If you like this function or
' thought it was helpful, drop me a note a
' nd tell me what you think.
'
function ClearOldRecords(myDSN, table_name, date_field, daysold)
' MAKE EXECUTION TRANSPARENT TO THE USER (on error resume next)
' Description: We want to execute a function but if the function fails we do not want the user to get an
' ugly error code, so we keep running the function and trap the error and send back a nice
' error code.
on error resume next
' CREATE THE GENERIC SQL STATEMENT FROM THE VARIABLES INPUTTED INTO THE FUNCTION
mySQL="Delete FROM " & table_name & " Where " & date_field & " >= dateAdd('d',now(), " & daysold & ")"
set DelX=server.createobject("adodb.connection")
DelX.open myDSN
set rmvodCards=DelX.execute(mySQL)
' TRAP THOSE PESKY ERRORS
' Description: This is where we determind if the executuion of the delete statement was ok or failed.
' in the statements below we basically say, if there is an error, return a negative 1
' and if there are no errors return a positive 1. Functions can return values unlike subs, so
' we set the name of the function ClearOldRecords equivalent to the output we want returned, in
' this case a 1 or a negative one.
if err.number then ' THE DELETE FAILED
ClearOldRecords = -1 ' EXECUTION FAILED
else
ClearOldRecords = 1 ' EVERYTHINGEXECUTED CORRECTLY
end if
end function
' EXAMPLE OF HOW TO EXECUTE THIS FUNCTIO
' N
'
showmyerrcodes = ClearOldRecords("DSN=card_queue", "card_queue", "b_time", "20")
' YOU MAY ALSO WANT TO DO THE FOLLOWING
if showmyerrcodes = 1 then
response.write "Execution successful"
else
response.write "Execution unsuccessful"
end if
%>
Far fare la cancellazione al sito però mi sembra un pò una scorciatoia, nel senso che se nessuno entra nella pagina i record non si cancellano. Se devi proprio cancellarli (poerchè la soluzione di filtrarli in visualizzazione non sarebbe affatto male), perchè non lo fai fare al db ? Però dipende da che db usi: se usi MicrosoftSQL puoi schedulare ogni sera alle 00:01 una query che cancella i record scaduti; non so altri db se hanno funzioni simili.
Ciao
infatti e un po complicato..uso access e possibile?
Che io sappia Access non ha questa funzionalità (e anche a intuito direi di no). Potresti fare tu un programmino in VB che metti nelle operazioni pianificate che svolge questa ed eventuali altre operazioni di manutenzione sul database (tipo la compattazione, se durante la giornata al tuo db vengono modificati pesantemente i dati). Questo programmino non avrà alcuna interazione con l'utente, semplicemnte parte, fa quello che deve fare (magari pilotato con dei parametri da linea di comando se avrai più di una operazione) e poi si chiude.
Poi ti ripeto, quando cancelli qualcosa è sempre la volta buona che ti serviva: perchè non li filtri nelle tue pagine i record scaduti (magari facendoti una vista e usando poi sempre quella in tutte le pagine) ?
Ciao
scusami non ho capito mi puoi fare un esempio?non esperto in asp......
Io consigliavo di fare un programmino (.exe) in VisualBasic, non in ASP. Nel tuo programmino avrai solamnete un modulo bas che apre la connessione al db, cancella i record scaduti, chiude la connessione al db e si chiude.
Lo scheduli nelle Operazioni Pianifiche di Windows (dal menù Accessori) del server web o del pc dove risiede l'applicazione web oppure il db.
Ciao