does sqldatasource insert method return anything like primary key?

Posted on 2006-03-21
Last Modified: 2007-12-19
i have a primary key column that is uniqueidentifier and has default to newID() or I have another table with autoincrment set to 1 for a primary key column of type int.  I was just wondering when using vs2005 and calling the insert method using the sqldatasource object if i can find out what key value the database assigned to the new row that was inserted?  i have tried cating the sqldatasource inserted event and not sure if the answer is in there or not?
Question by:joshuadavidlee
    LVL 12

    Accepted Solution

    Have you tried using output parameters? These can be used to get the identity after the insert. I could find one example on the web of this.

    the bit to note is the part:

              <asp:Parameter Name="contactName" Type="String" />
              <asp:Parameter Direction="Output" Name="contactID" Type="Int32" Size="4" />

    This uses a stored procedure to do the insert, which will assign @@IDENTITY to the parameter @contactID after the insert.

    LVL 12

    Expert Comment

    By the way, you want to be careful about using @@IDENTITY. It can, under certain circumstances, return a different identity value as it has server-level scope. Have a look at this to start off with understanding @@IDENTITY, SCOPE_IDENTITY() and IDENT_CURRENT() as well as INSERT ... OUTPUT:

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
    ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    729 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now