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

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
 
G

Guest

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,228
Members
46,818
Latest member
SapanaCarpetStudio

Latest Threads

Top