Using SELECT SCOPE_IDENTITY in an ad-hoc query

Last post 12-06-2008 8:09 AM by ghassan_aljabiri. 7 replies.

Sort Posts:

  • Using SELECT SCOPE_IDENTITY in an ad-hoc query

    07-24-2007, 8:00 AM

    I've got an insert command in an SqlDataSource control that looks like this:

    InsertCommand="INSERT INTO TAG2(TagText) VALUES (@TagText); SELECT SCOPE_IDENTITY()"

    Is this correct? How do I get at the value of the identity so I can use it in another insert command?
    Disco Patrick writes web applications using:

    Visual Studio 2008
    ASP.NET 3.5
    C#
    SQL Server 2008
  • Re: Using SELECT SCOPE_IDENTITY in an ad-hoc query

    07-24-2007, 9:52 AM
    • Contributor
      2,857 point Contributor
    • satya_tanwar
    • Member since 05-16-2007, 7:26 PM
    • USA (New York)
    • Posts 495
    Satya
    ------------------------------
    Mark as answer if you think
    this helped you Yes
  • Re: Using SELECT SCOPE_IDENTITY in an ad-hoc query

    07-24-2007, 9:59 AM

    Thanks Satya, but that link doesn't say anything about Execute Scalar. Did you type the right link?

    Disco Patrick writes web applications using:

    Visual Studio 2008
    ASP.NET 3.5
    C#
    SQL Server 2008
  • Re: Using SELECT SCOPE_IDENTITY in an ad-hoc query

    07-24-2007, 10:08 AM
    • Contributor
      2,857 point Contributor
    • satya_tanwar
    • Member since 05-16-2007, 7:26 PM
    • USA (New York)
    • Posts 495

    I typed the link coz it shows how to use identity field. ... read complete

    Satya
    ------------------------------
    Mark as answer if you think
    this helped you Yes
  • Re: Using SELECT SCOPE_IDENTITY in an ad-hoc query

    12-05-2008, 2:59 PM

    how to get the value programatically? without using sqldatasource

    GHS
  • Re: Using SELECT SCOPE_IDENTITY in an ad-hoc query

    12-05-2008, 9:07 PM
    • Star
      8,790 point Star
    • hans_v
    • Member since 01-29-2007, 9:03 PM
    • Posts 1,513
  • Re: Using SELECT SCOPE_IDENTITY in an ad-hoc query

    12-06-2008, 1:59 AM

    that is a great reference,

    but in all examples the returned id is integer , what if the returned id a uniqueidentifier?

    GHS
  • Re: Using SELECT SCOPE_IDENTITY in an ad-hoc query

    12-06-2008, 8:09 AM

    while i am googling i found this page , its the perfect solution

    http://vyaskn.tripod.com/retrieve_guid_value_like_identity.htm

    GHS
Page 1 of 1 (8 items)