Re: @@identity
- From: "Cor Ligthert [MVP]" <notmyfirstname@xxxxxxxxx>
- Date: Wed, 4 Jul 2007 19:34:59 +0200
Rad,
Why should it be a sproc and can it not dynamicly?
Cor
"Rad [Visual C# MVP]" <rad@xxxxxxxxxx> schreef in bericht
news:%2307vY8ZvHHA.2040@xxxxxxxxxxxxxxxxxxxxxxx
Kerry Moorman wrote:
Bill,Another alternative is to use a stored procedure to do the insert, and in
With SQL Server, Scope_Identity is more reliable than @@Identity.
One technique is to batch a Select Scope_Identity() statement with the
Insert statement. For a command object named cmd:
cmd.CommandText = "Insert Into ... ; Select Scope_Identity()"
Then, instead of using ExecuteNonQuery, use ExecuteScalar. To retrieve
the identity value into an ID variable:
ID = cmd.ExecuteScalar
Kerry Moorman
"Bill Gower" wrote:
I am using a ExecuteNonQuery() to insert a record into a SQL Server
database. How do I retrieve the identity value of the row just
inserted?
Bill
that procedure have an output parameter that will populate with the new
identity value.
--
http://bytes.thinkersroom.com
.
- Follow-Ups:
- Re: @@identity
- From: Rad [Visual C# MVP]
- Re: @@identity
- References:
- @@identity
- From: Bill Gower
- Re: @@identity
- From: Rad [Visual C# MVP]
- @@identity
- Prev by Date: Anyone notice how much faster DataAdapter.Fill() is than DataTable.Load(DataReader)?
- Next by Date: Re: @@identity
- Previous by thread: Re: @@identity
- Next by thread: Re: @@identity
- Index(es):
Relevant Pages
|