RE: C# SQL SERVER LAST INSERT ID EXAMPLES
From: Cowboy (Gregory A. Beamer) - MVP (NoSpamMgbworld_at_comcast.netNoSpamM)
Date: 01/24/05
- Next message: Cowboy (Gregory A. Beamer) - MVP: "RE: Sharing an OLE DB connection between MDI Parent and Children"
- Previous message: Cowboy (Gregory A. Beamer) - MVP: "RE: Lock Table"
- In reply to: Sheraz Khan via .NET 247: "C# SQL SERVER LAST INSERT ID EXAMPLES"
- Messages sorted by: [ date ] [ thread ]
Date: Mon, 24 Jan 2005 06:09:01 -0800
In a stored procedure, you can certainly get SCOPE_IDENTITY for an IDENTITY
column, or even query using the last row values, to get the last inserted ID
(with IDENTITY being easier). Only doing it on the last item is a bit
trickier, but you can ignore all other inserts, even though the value is
passed back 100% of the time. Another option is sending the data inserts as
XML. You lose a bit of perf, but you can answer the last row ID question
once, as the entire insert is batched.
Hope this helps spur some thought.
--- Gregory A. Beamer MVP; MCP: +I, SE, SD, DBA *************************** Think Outside the Box! *************************** "Sheraz Khan via .NET 247" wrote: > does anyone have sample code of data being inserted to a table, then the last insert id is retrived and inserted into another table. > > The Code is c# and the database is SQL SERVER, NO Access examples or vb... > > Thanks for this... i just cant find a simple example on this identity problem, people do try to help, but use the wrong conn types of languages.. > > thanks in advance > > Sheraz khan > sheraz.khan@learningtrust.co.uk > > ----------------------- > Posted by a user from .NET 247 (http://www.dotnet247.com/) > > <Id>SFXyGrABEkyVV0L0wg0ceg==</Id> >
- Next message: Cowboy (Gregory A. Beamer) - MVP: "RE: Sharing an OLE DB connection between MDI Parent and Children"
- Previous message: Cowboy (Gregory A. Beamer) - MVP: "RE: Lock Table"
- In reply to: Sheraz Khan via .NET 247: "C# SQL SERVER LAST INSERT ID EXAMPLES"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|