Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

"MoveLast" Equivalent in VB.Net 1

Status
Not open for further replies.

VBrian

Technical User
Mar 6, 2003
9
US
How does one determine the last record (with criteria)in a DataSet? My objective is to call up the last entry, matching certain criteria, and display the results. This was a simple task in VB6.0 with the statement:

Recordset.MoveLast

Is there a VB.Net equivalent? I understand that in VB.Net we are dealing with DataSets instead of Recordsets, but there must be a simple way to accomplish the same thing.

Any help on this is greatly appreciated.

VBrian

 
There isn't. You need to either loop the records (yawn), use the count property to find the last or use TOP in your SQL

TOP is my favourite for this job. Will minimise execution time.

Craig
 
Thank you for your reply Craig. Please forgive my ignorance, but I am still having problems accomplishing what I need to do. I have looked up "TOP" in VS.NET Help and the description of what it can do is there, but no examples of how to implement it into my SQL statement. I have tried every way I can think of and am not getting any positive results. Would it be too much to ask for a code sample of how this is done?

Also, is there a way to accomplish this objective using the OleDBDataReader?

Thanks again for your help.

Sincerely,

VBrian
 
VBrian,

Its used like this....

SELECT TOP (number of records|percentage) your statement

So you write your standard SQL, ordering it appropriately and then insert (in your case) TOP 1.

No problem using it with the reader. You simply set the command object to use the SQL defined. Will help speed your app too!

Craig
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top