简体   繁体   中英

How could I get the new ID of an inserted record in ASP.NET DetailsView using LinqDataSource

I've got the answer if I were using SqlDataSource by Overriding the Insert Statement and use the @@IDENTITY property, but when I use the LinqDataSource, I couldn't override the Insert statement!

so, the problem is:

I'm using ASP.NET Webform, DetailsViewControl in Insert Mode and LinqDataSource.

I want to retrieve the new ID of the inserted record. What's the easiest and the most efficient way to do that?

Thanks.

Using LinqDataSource.Inserted Event

Example from MSDN shows that newProduct.ProductID is the new ID.

protected void LinqDataSource_Inserted(object sender, LinqDataSourceStatusEventArgs e)
{
    if (e.Exception == null)
    {
        Product newProduct = (Product)e.Result;

        // newProduct.ProductID is the new ID
    }
    else
    {
        // Some Exception - e.Exception.Message;
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM