mastertrac
asked on
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
I need the c# code to retrieve the parameters value from my sql data source.
Thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
object obj = command.ExecuteScalar();
if (obj != null)
{
int id = int.Parse(obj.ToString());
}
Sql code
//
CREATE PROCEDURE [dbo].[CA_SP_InsertResourc
(
)
AS
BEGIN
INSERT INTO table....
select @@identity from table
END
GO