RE: C# SQL SERVER LAST INSERT ID EXAMPLES

From: Cowboy (Gregory A. Beamer) - MVP (NoSpamMgbworld_at_comcast.netNoSpamM)
Date: 01/24/05


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>
> 


Relevant Pages

  • OracleData provider for dot net gives ORA-01406:fetched column when fetching large string stored in
    ... We are using a column of long type Oracle Databse.This contains some string which sometimes exceeds to 60000 characters or more than that. ... But when we used a stored procedure having the same query, it generates the ORA-01406:fetched column value was truncated. ... I am attaching the sample code here. ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: Output Parameter To Global Variable (DTS)
    ... >article and used the dummy code. ... >end of the stored procedure thereby having the SP return a result set. ... Sorry, I am at a loss, as the sample code I posted previously works fine ... DTS - http://www.sqldts.com PASS - the definitive, global community for SQL Server professionals ...
    (microsoft.public.sqlserver.dts)
  • Re: mail merge problems
    ... sorry to post a question as a follow up to this query, ... I'm using the following sample code to do the same. ... oDataDoc = wrdApp.Documents.Add(ref Template, ref oMissing, ref ... oMissing, ref oFalse); ...
    (microsoft.public.access.queries)
  • Re: Desparete for advice on stored proc from asp.net
    ... > I have no hairs left and what is has gone gray. ... > I have a datagrid page which allows the user to select certain records ... within my stored procedure that gets called the ... here is sample code ...
    (microsoft.public.dotnet.framework.aspnet.datagridcontrol)
  • Re: Database problem
    ... > Use the following query ... > This will give you the record set of those companies that exist in table ... >> I have 2/different MDB database but in both the database I have a column ... >> Can someone please help me with this and please paste some sample code ...
    (microsoft.public.vb.general.discussion)