473,473 Members | 1,805 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Show the 4 last records in a table with asp

14 New Member
i tired do it alone but its gives me an eror like that:
"r object cant move back"

here is my code :
Expand|Select|Wrap|Line Numbers
  1. <%
  2. path = Server.mappath("../db/ServerData.mdb")
  3. set con = Server.createobject("ADODB.Connection")
  4. con.open "driver={Microsoft Access Driver (*.mdb)};DBQ="&path
  5. set r = con.execute("select * from News")
  6. Dim i
  7. i = 1
  8. r.MoveLast
  9. do until i = 4 Then
  10. Response.write (""&r.fields("Name")&"")
  11. r.MovePrevious
  12. loop
  13. conn.close
  14. conn = Nothing
  15. %>
Apr 5 '10 #1
5 1927
GazMathias
228 Recognized Expert New Member
You aren't working with a recordset, so you can't move back through it.

Learn about recordsets here

Gaz
Apr 5 '10 #2
jhardman
3,406 Recognized Expert Specialist
Even when you start working with recordsets, the default cursor is forward only. Either query in such a way that you start with the newest, or specify a cursor that can move both ways.

Jared
Apr 5 '10 #3
asdasd10
14 New Member
so how i should write it?
Apr 5 '10 #4
jhardman
3,406 Recognized Expert Specialist
the tutorial at w3schools that Gaz posted is a good place to start. in brief:
Expand|Select|Wrap|Line Numbers
  1. <%
  2. path = Server.mappath("../db/ServerData.mdb")
  3. set con = Server.createobject("ADODB.Connection")
  4. con.open "driver={Microsoft Access Driver (*.mdb)};DBQ="&path
  5.  
  6. set r = server.createobject("ADODB.recordset")
  7. r.open "select * from News", con, 2,3
  8. Dim i
  9. i = 1
  10. r.MoveLast
  11. do until i = 4 Then
  12. Response.write (""&r.fields("Name")&"")
  13. r.MovePrevious
  14. loop
  15. conn.close
  16. conn = Nothing
  17. %>
the 2,3 on the r.open line is what specifies which type of cursor you are using. This actually gives you one that can make edits to the db, and that's probably not what you want. the w3schools site gives more details, and some examples of what constants to use there.

Jared
Apr 5 '10 #5
asdasd10
14 New Member
thanks all i managed what i want to do
Apr 5 '10 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Ricardo | last post by:
Hi all, I am trying to come up with a sql query (just one query) that returns all the columns for the last N records that were inserted into a table. I have a column in the table that has the...
20
by: Guru | last post by:
Hi I have a table which contains number of rows. I want to fetch the last 5 records from the table. I know for the first 'n' records we can use FETCH FIRST n ROWS ONLY command. But i want to...
3
by: AndyBell | last post by:
Hi all! I have an Access 2000 database for the Habiat for Humanity where I work. This is the second database I have written and it gets a bit more complex each time... I have learned much and...
0
by: Tom Kaminski [MVP] | last post by:
I want to show a table of master records, with the right most column displayed as a comma (or space) delimited list of details. The practical application of this is a thesaurus, where the master...
15
by: Joachim | last post by:
Hi, Als a beginner, I am looking for a way to show records My code is Private sub Connection( Dim odbconn_Pro As OleDbConnectio Dim odbcomm_Pro As OleDbComman Dim odbdare_Pro As...
1
by: Galka | last post by:
Hello I have a form to enter names and some other personal information. When a name is entered, it is checked against existing records: maybe, such name was entered before? If yes, user is...
6
by: Christo | last post by:
I have this script for showing news on a page, but i want it to only show the last 10 records, as in the 10 records that were added to the database last. the script shows the entries in descending...
6
by: gerbski | last post by:
Hi all, I am relatively new to ADO, but up to now I got things working the way I wanted. But now I've run into somethng really annoying. I am working in MS Access. I am using an Access...
4
by: kdubble | last post by:
Hi I am trying to get the results of a query to show only unique student records (not duplicates). Is there a simple way to make the criteria field do this? I am not too familiar with SQL. ...
2
by: banderson | last post by:
Hello, I have a data entry form for a table with information about buildings and am having a problem making a combo box do what I want. I would like to make the combo box show a list of unique bldg...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.