Solved

help with if statement

Posted on 2006-10-30
3
132 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

I still run into .cgi files every now and then. In some instances, I actually prefer the simplicity of a .cgi script to other options. Since I use DreamWeaver extensively, what I needed was a way to open .cgi scripts in Dreamweaver. And I wanted to …
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…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

856 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