Home > SQL Development > Display last record from database

Display last record from database



<i><b>Originally posted by : Ly (hwatts@hotmail.com)</b></i><br /><br />Hi,<br /><br /> I try to display the last record from database by using:<br /> 1. RS.movelast before response.write<br /> It gave the error message:<br />Error Type:<br />Microsoft OLE DB Provider for ODBC Drivers (0x80040E24)<br />Rowset does not support fetching backward.<br /><br /> 2. Then I try another way by:<br />Select id,info from table order by id<br /> It's displayed the first record instead of last.<br /><br />Can any one help.<br />Thanks,<br /><br />Ly

    
Guest


<i><b>Originally posted by : </b></i><br />Try..<br />Select id,info from table order by id desc<br />Bye<br />Jyothsna<br /><br />------------<br />Ly at 5/10/2001 5:15:33 PM<br /><br /><br />Hi,<br /><br /> I try to display the last record from database by using:<br /> 1. RS.movelast before response.write<br /> It gave the error message:<br />Error Type:<br />Microsoft OLE DB Provider for ODBC Drivers (0x80040E24)<br />Rowset does not support fetching backward.<br /><br /> 2. Then I try another way by:<br />Select id,info from table order by id<br /> It's displayed the first record instead of last.<br /><br />Can any one help.<br />Thanks,<br /><br />Ly

Was this answer helpful ? Yes No   
Guest


<i><b>Originally posted by : Fred Schenk</b></i><br />Or, more efficient:<br /><br />SELECT TOP 1 id,info FROM table ORDER BY id DESC<br /><br />if you only want the last one...<br /><br />Gtx,<br /> Fred<br /><br />------------<br /> at 5/11/2001 3:36:13 PM<br /><br />Try..<br />Select id,info from table order by id desc<br />Bye<br />Jyothsna<br /><br />------------<br />Ly at 5/10/2001 5:15:33 PM<br /><br /><br />Hi,<br /><br /> I try to display the last record from database by using:<br /> 1. RS.movelast before response.write<br /> It gave the error message:<br />Error Type:<br />Microsoft OLE DB Provider for ODBC Drivers (0x80040E24)<br />Rowset does not support fetching backward.<br /><br /> 2. Then I try another way by:<br />Select id,info from table order by id<br /> It's displayed the first record instead of last.<br /><br />Can any one help.<br />Thanks,<br /><br />Ly

Was this answer helpful ? Yes No   
Guest


No, no. You must be using adForwardOnly as a connection param. And at the same time you must already be beyond the end of the recordset so that MoveLast means actually move back by one position.



1) change conn params so they support scrolling backwards

2) Did you check for EOF? If your recordset doesn't contain records you are at EOF which is again beyond the last record and MoveLast would ask to move backwards

Was this answer helpful ? Yes No   
Guest
 
 
Home - About Infoqu - Contact - Privacy Statement - Link to Infoqu - Bookmark Infoqu

Copyright 2007-2008 by Infoqu. All rights reserved