2010-05-02 97 views
0

我有這樣的代碼。Linq To Sql - DataContext.SubmitChanges()問題

DBContext是Datacontext實例。

try 
      { 
       TBLORGANISM org = new TBLORGANISM(); 
       org.OrganismDesc = p.Subject; 
       DBContext.TBLORGANISMs.InsertOnSubmit(org); 
       DBContext.SubmitChanges(); 
      } 
      catch (Exception) 
      { 
      } 

在這一點上,我想IGNORE錯誤,並希望被跳過。不要重試。 但當我嘗試另一個插入像

   TBLACTION act = new TBLACTION(); 
       act.ActionDesc = p.ActionName; 
       DBContext.TBLACTIONs.InsertOnSubmit(act); 
       DBContext.SubmitChanges(); 

的SubmitChanges先試一次嘗試。

如何判斷「跳過錯誤,不要再試一次」?

回答

1

第二次創建一個新的DBContext實例。

但爲什麼你想跳過錯誤?

1

試試這個:DBContext.SubmitChanges(ConflictMode.ContinueOnConflict)。 希望它會有所幫助。