How to retrieve Scope_Identity parameter in ItemInserted Event

I wish to use a FormView to insert a record but then stay on the same page but change to edit mode.  I understand I have a stored proc to do the insert that that has a select Scope_Identity() statement at the end.  I also understand that I need to use the ItemInserted event to retrieve the Identity value.  

I need the c# code to retrieve the parameters value from my sql data source.

Thanks
mastertracAsked:
Who is Participating?
 
Guy Hengel [angelIII / a3]Connect With a Mentor Billing EngineerCommented:
as small addition to above procedure code:

CREATE PROCEDURE [dbo].[CA_SP_InsertResource]
(      
)
AS

BEGIN
   SET NOCOUNT ON
      INSERT INTO table....
      select @@identity from table
END
GO
0
 
sabeeshCommented:
C#
object obj = command.ExecuteScalar();
                    if (obj != null)
                    {
                        int id = int.Parse(obj.ToString());
                    }

Sql code
//

CREATE PROCEDURE [dbo].[CA_SP_InsertResource]
(
      
)
AS

BEGIN
      INSERT INTO table....
      select @@identity from table
END
GO
0
 
mastertracAuthor Commented:
I understand the sqlcode.  However, I was led to believe that I could let the .net FormView and SqlDataSource d the inserting of the record using the stored procedure and then in the ITEMINSERTED event retrieve the identity through a parameter or something.  So the C# code above doesn't make sense in this scenario. I know how to use executeSaler but I want to let the the formview insert the record for me, retrieve the identity, then using the identity change to edit mode.   Is this possible?  I just tried doing an executescaler in the ItemInserted event of the formview and it did not retrieve the identity.
0
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.