Wrox Programmer Forums
Go Back   Wrox Programmer Forums > SQL Server > SQL Server ASP
|
SQL Server ASP Discussions about ASP programming with Microsoft's SQL Server. For more ASP forums, see the ASP forum category.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server ASP 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 March 18th, 2004, 12:38 AM
Authorized User
 
Join Date: Mar 2004
Posts: 47
Thanks: 0
Thanked 0 Times in 0 Posts
Default Get last item in the database using asp.net

How am I going to retrieve the last item in a table in a database (SQL Server) using ASP.NET. Can anybody help me with this? Thanks

 
Old March 18th, 2004, 05:27 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

If you mean the last row entered there is no generic way without knowing the names and types of the fields.

--

Joe
 
Old March 18th, 2004, 05:56 AM
Authorized User
 
Join Date: Mar 2004
Posts: 47
Thanks: 0
Thanked 0 Times in 0 Posts
Default

May i know whether eof is still working in asp.net? cos i've tried it once to get the last item inserted in a table (lets say a customer name in a table call customer) but failed. i've tried to use an automatic generic integer as to assist me to fetch the last item using SQL statement (select max(customerId) from customer). but besides this method, do we still have any other method? Any help will be appreciated.

 
Old March 18th, 2004, 05:13 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Which of these question do you mean?

A) How do I get the last row in a DB table using ASP.NET?
or
B) How do I get the last row INSERTED INTO a DB table using ASP.NET?

A) The database objects used in .NET are much more powerful than those used in ASP (ADODB). There are many ways to answer the first question.

B) This is a completely different situation. There is no built it way to ask the database for "the last inserted row". You would need to figure that out based on the data within. If you use an identity field in the table, than you could ask for the row with a simple query:

select * from table where rowid=(select max(rowid) from table)

Or it could be based on date if you have a date field...

select * from table where CreateDate=(select max(CreateDate) from table)

This is all up to how your data is stored.

Peter
------------------------------------------------------
Work smarter, not harder.
 
Old March 18th, 2004, 09:55 PM
Authorized User
 
Join Date: Mar 2004
Posts: 47
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks Peter, I understand what you are try to tell me. This information helps me a lot






Similar Threads
Thread Thread Starter Forum Replies Last Post
localizing the database using asp.net 2.0 [email protected] ASP.NET 2.0 Basics 2 November 27th, 2008 10:42 AM
Converting database using asp.net prajesh_jha ADO.NET 2 April 28th, 2005 09:31 AM
Database diagram in .net using asp.net,c#.net scotttiger ADO.NET 2 February 16th, 2005 01:35 AM
Database Connection Problem with ASP.NET fukai100 Classic ASP Databases 2 August 13th, 2004 12:12 PM





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