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

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:
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.