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 August 11th, 2004, 09:53 PM
Authorized User
 
Join Date: Mar 2004
Posts: 84
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to gmoney060 Send a message via MSN to gmoney060
Default Selection Problem

I need to select the whole recordset that has the greatest date value in the "DatePosted" column. This works, but if there is no value there, or there is only one recordset I get an error... What is a better way of doing this?

Code:
    Sub LastPost()
    Dim RsLastPost : Set RsLastPost = Server.CreateObject("ADODB.RecordSet")
    RsLastPost.Open "Select * From Posts Where ForumID="&SubCat("SubCatID")&" Order by DatePosted Asc",ObjConn,1,2
    RsLastPost.MoveLast
    Dim DatePosted : DatePosted = Split(RsLastPost("DatePosted")," ", -1,1)
    Response.Write("<Strong>"&DatePosted(0)&"</Strong>: "&DatePosted(1)&" "&DatePosted(2)&"")
    Response.Write("<br>")
    Response.Write("By: <a class=LinkTableText href=profile.asp?UserName="&RsLastPost("UserName")&">"&RsLastPost("UserName")&" </a>")
    Response.Write("<a href=topic.asp?TopicID="&RsLastPost("TopicID")&"&ForumID="&RsLastPost("ForumID")&"><img src=/images/icon_lastpost.gif border=0></a>")
    RsLastPost.Close
    Set RsLastPost = Nothing
    End Sub


 
Old August 11th, 2004, 11:11 PM
Friend of Wrox
 
Join Date: Sep 2003
Posts: 363
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hello,

  After issuing rs.open, check for the record pointer position.
If the query retrieves any records, the record pointer is at the first record position. If no records are retrieved the pointer is at BOF or EOF.

So you can test like

if not rs.bof then
' rs.movelast
' Your coding
end if

This is always needed when retriving the data from recordset. Other wise you get runtime error.



 
Old August 12th, 2004, 12:25 PM
Authorized User
 
Join Date: Mar 2004
Posts: 84
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to gmoney060 Send a message via MSN to gmoney060
Default

Thanks a lot, that worked





Similar Threads
Thread Thread Starter Forum Replies Last Post
Sorting and record Selection problem in GridView Dmitriy ASP.NET 3.5 Professionals 0 September 24th, 2008 03:18 PM
DropDown Value Selection problem....... dharmeshtandel ASP.NET 2.0 Basics 0 May 15th, 2008 07:27 AM
MSHFlexgrid Row selection problem spmano1983 Beginning VB 6 0 August 17th, 2007 01:23 AM
Problem in retreiving muliti selection list AsadRaza Classic ASP Basics 1 February 18th, 2007 09:03 PM
ListBox Value Selection problem caterpillar General .NET 0 July 26th, 2006 11:41 AM





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