Solved

help with if statement

Posted on 2006-10-30
3
129 Views
Last Modified: 2010-04-25
I have an include file which deletes records which are more than 14 days old. I was having the problem that if there were no records in the database the page would not display. To stop this I put in another if statment saying that if the recordcount was more than zero then run the delete command. If the database is empty the page works fine. The problem now is that my delete old records program never runs now. If I remove the new if then statement the delete old records program runs fine. Can someone take a look at this and tell me what I'm doing wrong?

<%
Dim rsdeleteoldcomputers
Dim rsdeleteoldcomputers_numRows

Set rsdeleteoldcomputers = Server.CreateObject("ADODB.Recordset")
rsdeleteoldcomputers.ActiveConnection = MM_glowfish_STRING
rsdeleteoldcomputers.Source = "SELECT * FROM sellcomputers ORDER BY currentdate ASC"
rsdeleteoldcomputers.CursorType = 0
rsdeleteoldcomputers.CursorLocation = 2
rsdeleteoldcomputers.LockType = 1
rsdeleteoldcomputers.Open()

rsdeleteoldcomputers_numRows = 0
%>

<%
If rsdeleteoldcomputers.Recordcount>0 then      <<<<<<AFTER ADDING THIS THE DELETE PROGRAM WONT RUN>
DIM NewsDate
NewsDate = rsdeleteoldcomputers.Fields.Item("currentdate").Value
IF NewsDate<DateAdd("d", -14, DATE()) THEN
%>

<%

set comdeleteoldcomputers = Server.CreateObject("ADODB.Command")
comdeleteoldcomputers.ActiveConnection = MM_glowfish_STRING
comdeleteoldcomputers.CommandText = "DELETE sellcomputers.ID, sellcomputers.currentdate, sellcomputers.item, sellcomputers.price, sellcomputers.city, sellcomputers.wantedselling, sellcomputers.name, sellcomputers.address, sellcomputers.description, sellcomputers.telephone, sellcomputers.email FROM sellcomputers WHERE (((sellcomputers.currentdate)<DateAdd('d',-14,Now()))) "
comdeleteoldcomputers.CommandType = 1
comdeleteoldcomputers.CommandTimeout = 0
comdeleteoldcomputers.Prepared = true
comdeleteoldcomputers.Execute()

%>

<%END IF%>

<%
end if
rsdeleteoldcomputers.Close()
Set rsdeleteoldcomputers = Nothing
%>
0
Comment
Question by:elliottbenzle
3 Comments
 
LVL 16

Expert Comment

by:CWS (haripriya)
ID: 17839999
If you are not doing anyother process other than deleting the records, then no need to open the recordset itself,

<%
Dim comdeleteoldcomputer

set comdeleteoldcomputers = Server.CreateObject("ADODB.Command")
comdeleteoldcomputers.ActiveConnection = MM_glowfish_STRING
comdeleteoldcomputers.CommandText = "DELETE sellcomputers.ID, sellcomputers.currentdate, sellcomputers.item, sellcomputers.price, sellcomputers.city, sellcomputers.wantedselling, sellcomputers.name, sellcomputers.address, sellcomputers.description, sellcomputers.telephone, sellcomputers.email FROM sellcomputers WHERE ((sellcomputers.currentdate)<DateAdd('d',-14,Now()))"
comdeleteoldcomputers.CommandType = 1
comdeleteoldcomputers.CommandTimeout = 0
comdeleteoldcomputers.Prepared = true
comdeleteoldcomputers.Execute()

%>

Let me know if this does not work.
0
 
LVL 10

Accepted Solution

by:
aplimedia earned 500 total points
ID: 17848929
Try this instead of > 0. Simply use .EOF (End of file) like this.

rsdeleteoldcomputers.LockType = 1
rsdeleteoldcomputers.Open()

If Not rsdeleteoldcomputers.EOF Then ' <<<<<<<<<<<<<<  If there are records... dont forget to put an end if at the end of your delete sequence.

rsdeleteoldcomputers_numRows = 0
%>

Kind Regards

Aplimedia
0
 
LVL 4

Author Comment

by:elliottbenzle
ID: 17855983
If Not rsdeleteoldcomputers.EOF Then

works great thanks
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

For those who don't know, Adobe Dreamweaver is a popular commercial web editor that enables you to design, build and manage complex websites. The editor is a WYSIWYG (What You See Is What You Get) web editor, which means that you can create your web…
Adobe Dreamweaver CS5 is a WYSIWYG web page editor that has advanced HTML, CSS, and Javascript rendering functionality and is probably the most well-known HTML editor available. Much of Dreamweaver's appeal centers around the Design View interfac…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now