I'm trying to get the right code so that only the 5 latest additions to my db are displayed, and displayed in descending order (last in, first out). I'm very new to this and have no real idea as to why it isn't working. I'm running PWS on win98se. The code is listed below:
Code:
<%
'Dimension variables
Dim adoCon 'Holds the Database Connection Object
Dim rsNews 'Holds the recordset for the records in the database
Dim strSQL 'Holds the SQL query to query the database
Dim iRowCounter
'Create an ADO connection object
Set adoCon = Server.CreateObject("ADODB.Connection")
'Set an active connection to the Connection object using a DSN-less connection
adoCon.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("db/rafpnews.mdb")
'Create an ADO recordset object
Set rsNews = Server.CreateObject("ADODB.Recordset")
'Initialise the strSQL variable with an SQL statement to query the database
strSQL = "SELECT * FROM tblNews order by NewsID desc;"
'Open the recordset with the SQL query
rsNews.Open strSQL, adoCon
'Loop through the recordset
Do While not rsNews.EOF
'Write the HTML to display the current record in the recordset
for iRowCounter = 1 to 5
Response.Write ("<br><span class='newstitle'>")
Response.Write (rsNews("Title"))
Response.Write ("</span><br><span class='newsdate'>")
Response.Write (rsNews("Date"))
Response.Write ("</span><br><span class='newstype'>")
Response.Write (rsNews("Type"))
Response.Write ("</span><br><span class='newstext'>")
Response.Write (rsNews("Text"))
Response.Write ("</span>")
'Move to the next record in the recordset
rsNews.MoveNext
next
Loop
'Reset server objects
rsNews.Close
Set rsNews = Nothing
Set adoCon = Nothing
%>
Running this code displays all the records and gives me the following error msg:
Quote:
quote:ADODB.Field error '80020009'
|
Quote:
Either BOF or EOF is True, or the current record has been deleted. Requested operation requires a current record.
?
|
Any help will be appreciated!
etv
I drink, therefore I am.