开发者

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开发者_如何学C 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;
    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜