does sqldatasource insert method return anything like primary key?

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?
joshuadavidleeAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

AGBrownCommented:
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.

http://dotnetjunkies.com/QuickStartv20/util/srcview.aspx?path=~/aspnet/samples/data/RetValAndOutputParamsInsert.src

the bit to note is the part:

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

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

Andy

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
AGBrownCommented:
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:

http://www.dbazine.com/sql/sql-articles/cook18
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.