如何使用 LinqDataSource 获取 ASP.NET DetailsView 中插入记录的新 ID

发布于 2024-11-11 16:09:34 字数 246 浏览 3 评论 0原文

如果我通过覆盖 Insert 语句并使用 @@IDENTITY 属性来使用 SqlDataSource,我就得到了答案,但是当我使用 LinqDataSource 时,我无法覆盖 Insert 语句!

所以,问题是:

我正在使用 ASP.NET Webform、插入模式下的 DetailsViewControl 和 LinqDataSource。

我想检索插入记录的新 ID。最简单、最有效的方法是什么?

谢谢。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

谁许谁一生繁华 2024-11-18 16:09:34

使用 LinqDataSource.Inserted 事件

MSDN 中的示例显示 newProduct.ProductID 是新 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;
    }
}

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;
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文