Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

help with if statement

Posted on 2006-10-30
3
Medium Priority
?
136 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 2000 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: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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

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 …
This article is very specific and is only intended to help if you are installing Dreamweaver 8 in a Windows 7 environment with Office 2007 installed.   I'm not sure why Microsoft tends to release OS' that should not be released but they do.  Windows…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

618 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