Home All Groups Group Topic Archive Search About

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

Author
2 Jan 2006 9:12 PM
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

Author
25 Jan 2006 2:21 AM
James
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.

Show quoteHide quote
"Craig" wrote:

> 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
>
>
>