Wrox Programmer Forums
|
Classic ASP Databases Discuss using ASP 3 to work with data in databases, including ASP Database Setup issues from the old P2P forum on this specific subtopic. See also the book forum Beginning ASP.NET Databases for questions specific to that book. NOT for ASP.NET 1.0, 1.1, or 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Databases section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 23rd, 2004, 08:30 AM
Registered User
 
Join Date: Oct 2004
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default delete data when date expires

hi..

im doing a event calendar now. and much of the information have to be entered and stored into the database. however, the data and information will be redundant when the event past or expires. is there any code whereby i can set and automatically delete the data from the database once the event has past?

 
Old October 24th, 2004, 05:59 AM
Friend of Wrox
 
Join Date: Sep 2003
Posts: 363
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hi,


  Write an VBS file to delete records from the database. set the scheduled tasks to run this file.


-------------
Rajani

 
Old October 24th, 2004, 08:59 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

What is the database that is involved in this? Is that SQL server or MS Access? You haven't mentioned about that. If SQL server, you can schedule an job on sql server(under Enterprise Manager >> ServerName >> Management >> SQL server Agent >> Jobs) to run once everyday that checks for past events and deletes. For this you need to have SQL server agent running.

You can use something like this in the job and schedule it to run at a time when there is less load/operation on the server(sometime during midnight or at 12:00 am everyday).
Code:
Delete from TABLE_NAME where DATECOLUMN < getdate()-7
This deletes the rows all that are older than 7 days from now, thus keeps a week's old records always. Reduce/Increase 7 to a lower/higher value that suits your requirement.

If that is MS access, that is best done as RajaniKrishna suggested. Create a vbscript file that does the same and schedule a task on the OS at similar time. Running that daily or weekly would be left to your preference.

Cheers!

_________________________
- Vijay G
Strive for Perfection
 
Old October 24th, 2004, 08:04 PM
Registered User
 
Join Date: Oct 2004
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

hi and thanks for ya reply

im using MS Access for now.

can you explain about running the VS script? im kinda new, so i don't really understand ya explanation. thanks

 
Old October 24th, 2004, 08:17 PM
Friend of Wrox
 
Join Date: Sep 2003
Posts: 363
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hi this is a sample VBS file to delete data from the database.


on error resume next
dim conn,rs,str1
set conn=createobject("adodb.connection")
conn.provider="Microsoft.Jet.Oledb.4.0"
conn.open "\\rajani\donfranco\production\attendance\emp. mdb"
conn.beginTrans
str1="delete from attendance"
conn.execute str1
str1="insert into attendance(eventdate,eventtime,cardnumber) select eventdate,eventtime,cardno from EventListTable in '\\rajani\database\CipherAccess.mdb' where len(cardno)>0"
conn.execute str1

if Err.number <> 0 then
    conn.rollbackTrans
else
    conn.commitTrans
end if
conn.close
set conn=nothing


Go to windows scheduler and run this file as per u r requirements(daily/weekly).


--------------
Rajani

 
Old October 25th, 2004, 04:57 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hi,
Code:
strSql = "select count(*) as cnt from Table1 where col2 < date()-7"
'strSql = "delete from Table1 where col2 < date()-7"
set con = createobject("adodb.connection")
constr="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=db1.mdb;User Id=admin;Password=;"
con.open constr

'con.Execute(strSQL)

set rs = con.Execute(strSQL)
wscript.echo rs("cnt")
rs.close
set rs = nothing
con.close
set con = nothing
Create a vbscript file with extension .vbs and add the code given above here.

Then create a batch file and add the following code in it.
Code:
cscript yourvbscript_filename.vbs
open command prompt and execute the batch file in there. See if that gives the count of rows that are older than 7 days. If that seems to be correct, then UNCOMMENT the code that is in GREEN in the VBS file code shown above. And COMMENT all the lines that are marked in BLUE.

NOTE : All that marked in RED in the above code are subject to change based on your setup there.

Then open up control panel and under schedule tasks, add a new task that runs this batch file once every day or every week. That should be what you are looking for.

Hope that explains.
Cheers!

_________________________
- Vijay G
Strive for Perfection
 
Old October 27th, 2004, 12:34 AM
Registered User
 
Join Date: Oct 2004
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

thanks for ya help! Appreciate all!






Similar Threads
Thread Thread Starter Forum Replies Last Post
How to delete all data from table TomW Access VBA 5 March 12th, 2008 09:11 AM
Delete by Date tad_at_work SQL Server 2005 5 May 21st, 2007 12:19 AM
Auto delete by date XXL PHP How-To 1 March 29th, 2006 01:32 AM
How can i Insert , delete data from datagrid ?? jay4ever_2000 ASP.NET 1.0 and 1.1 Professional 1 February 17th, 2006 03:35 PM
Cannot modify (add/change/delete) data jandarby Classic ASP Databases 9 June 4th, 2003 06:25 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.