Freeware and Shareware Downloads Tech Articles and Forum Technology News Contact File Champ
 
Google
 
 
Computer Software > Programming
Author Message
admin
Posts: 7
Member Since: 3/1/2005
Subject: Get Autonumber Field Value in ASP.NET Posted On: 4/4/2005 8:00:00 AM

To get an autonumber field value from a database using ASP.NET (ADO.NET) connected mode, all you have to do is issue the following command after your INSERT statement:

SELECT @@IDENTITY

Here's a complete sample of the code:

cmd.CommandText = "INSERT INTO Users (Username, Password) VALUES ('anyusername', 'anypassword')"
cmd.ExecuteNonQuery()
cmd.CommandText = "SELECT @@IDENTITY"
intUserID = cmd.ExecuteScalar
Computer Software > Programming
Guests Online: 81
Users Online: 0
Registered Users: 3591
Articles: 8