Use this:
SELECT IDENT_CURRENT('YourTableNa
Main Topics
Browse All TopicsHi
I have table with an incremented id as primary key
I need to retrive the scope_identity before i do the insert
Dim sSql As String = "SELECT scope_identity()"
Dim cmd As SqlCommand = m_con.CreateCommand
cmd.CommandText = sSql
Return CInt((cmd.ExecuteScalar())
This though returns a system.db.null
How do i get the id ?
thanks
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
>Use this:
>SELECT IDENT_CURRENT('YourTableNa
will not be transaction safe, so you query that value, and would use +1 for example, another session could have done the same in parallel...
>but if i then do an insert and get the scope id -
>am i then able to do an update on that particular created row
yes
No, my question was how to get/create an id within my session as i can risk that other sessions creates there own
id's
so why i wanted to avoid SELECT IDENT_CURRENT due to
another user/session does id+1 in the same parallel
but thank you for responding to my question( i know its quite bad formulated-please excuse me for that)
and i do ussually do split point when different inputs contributes to the solution.
Business Accounts
Answer for Membership
by: angelIIIPosted on 2008-04-03 at 06:26:20ID: 21272353
>scope_identity before i do the insert
no. you run scope_identity AFTER the insert, and it will return the value generated by that insert (must be on the same connection).