retrirving @@identity using ado.net

  • Thread starter Thread starter vadim
  • Start date Start date
V

vadim

Hi,

I am writing an asp.net app, where I insert some data into a table that
contains an identity column ID and I need to know after the insert what was
the ID value just created. In my Client server development I usually use
select @@identity to get this info, but it doesn't work in ado.net.

Here is what I do
-open connection
- use sql command to execute non query
- create another instance of sql command using the same connection and this
sql command contains select @@Identity query
- then I get sqldatareader from sqlcommand.executereader
- and if reader.read I am trying to getvalue(0), it contains errors.

What am I doing wrong here?

Thank you

Vadim
 
Try this
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide
/html/cpconRetrievingIdentityOrAutonumberValues.asp

Thx Daren
MCSD.NET

-----Original Message-----
From: vadim [mailto:vadim@dontsend]
Posted At: Wednesday, 8 December 2004 1:42 PM
Posted To: microsoft.public.dotnet.framework.adonet
Conversation: retrirving @@identity using ado.net
Subject: retrirving @@identity using ado.net


Hi,

I am writing an asp.net app, where I insert some data into a table that
contains an identity column ID and I need to know after the insert what
was the ID value just created. In my Client server development I usually
use select @@identity to get this info, but it doesn't work in ado.net.

Here is what I do
-open connection
- use sql command to execute non query
- create another instance of sql command using the same connection and
this sql command contains select @@Identity query
- then I get sqldatareader from sqlcommand.executereader
- and if reader.read I am trying to getvalue(0), it contains errors.

What am I doing wrong here?

Thank you

Vadim
 
Back
Top