Retrieving the value of the identity field of a newly inserted record?

  • Thread starter Thread starter Craig
  • Start date Start date
C

Craig

In ASP.NET 2.0 and the formview control how do you get the value of the
identity field of a newly inserted record?

In ASP.NET 1.1 after the new record was saved you just said
intNewIdentityID = Dataset.tblMtTable.IndentityID
Simple but can't seem to do it in the formview.



Thanks
 
You need to create an event handler for the DataSource Control that the
FormView Control is bound to. In the Properties for the DataSource Control,
view the Events (Lightning Bolt) and double click on the "Inserted" event.
This will create the handler.

This event is raised when a record is inserted. Within the handler add...

int Id = e.Command.Parameters["@WhatYouNamedReturnParam"].Value

This will grab the Id value of the inserted record as long as you set it up
in the stored procedure.
 
Back
Top