Reputation: 173
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.
Upvotes: 0
Views: 1088
Reputation: 31260
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;
}
}
Upvotes: 2