Link to home
Start Free TrialLog in
Avatar of ipokkel
ipokkel

asked on

Finding the autoid number of a sql insert query (.net frameowork)

is it possible to find the autoincrement id of a record that has been inserted without doing another call to the database. I need to be able to do this in asp.net.

Here is an example:
The table consists of three columns; id (autoincrement), username, password

Dim oConn As sqlConnection
Dim oCmd As sqlCommand
Dim SQLQuery As String

SQLQuery = "INSERT INTO TB_Names "
SQLQuery = " (username, password) " & _
                   " Values('kevin','password')

oCmd = new SqlCommand(SQLQuery)
oCmd.Connection = oConn
oConn.Open()
oCmd.ExecuteNonQuery()
oCmd.Connection.Close()

surely there should be something like oCmd.max(id)
SOLUTION
Avatar of sybe
sybe

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial