• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 661
  • Last Modified:

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
0
mastertrac
Asked:
mastertrac
  • 2
2 Solutions
 
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
 
Guy Hengel [angelIII / a3]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
 
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

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now