2011-06-02 25 views

回答

2

使用從MSDN LinqDataSource.Inserted Event

實施例顯示,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; 
    } 
} 
+0

我不想觸發一個新的查詢來獲取新的ID,我想覆蓋INSERT語句或使用另一個神奇的工具! – 2011-06-02 23:02:52

+0

它不會觸發新的查詢。在執行數據源的insert語句後觸發此事件。 – 2011-06-02 23:05:26

+0

啊哈,看起來不錯!謝謝@amit_g – 2011-06-02 23:10:01

相關問題