Click to See Complete Forum and Search --> : SQL2005 Automatic increment ID


lhayes00
October 23rd, 2006, 12:05 PM
Hi,

I have several database tables which were created within the Visual Web Developer 2005 Express Edition IDE. I have set up the ID field for automatic incrementing with the "Identity Specification" properties.

When an ASP.NET page loads, how can I find what the next ID would be, should a record be created?

Lea Hayes

Niranos
October 23rd, 2006, 02:03 PM
There are few solutions of this problem, depends on for what u need this Id .
You can :

1) read max id when page start (in Page_Load), and keep it In session state,
2) or read max id after adding new record into table and keep it in session too,
3) or read all id that You will need on your web application start,


To select last ID in your tables u can use this Sql statement:

SELECT MAX(ID) as MaxId FROM YourTableName

lhayes00
October 23rd, 2006, 02:09 PM
Hi,

Thanks for that, the SQL statement you gave me seems to solve my problem. :)

Best regards,
Lea Hayes

Niranos
October 23rd, 2006, 02:21 PM
Hi, I’m glad I can help ^^