2013-12-11 95 views
1

我用一個TableAdapter更新這樣的數據庫:TableAdapter的不更新標識

var changes = anpDatabase.AnpCollection.GetChanges(); 
anpCollectionTableAdapter.Update((AnpDatabase.AnpCollectionDataTable)changes); 
anpDatabase.AnpCollection.Merge(changes); 
anpDatabase.AnpCollection.AcceptChanges(); 

然而,這是不夠的,更新標識主列...我試圖把改變適配器插入命令以下幾點:

INSERT INTO AnpCollection 
        (ParentCollectionId, StartDate, EndDate, Completed, IsPartial, Partitioned, IsAutomaticallyGenerated) 
VALUES  (@ParentCollectionId,@StartDate,@EndDate,@Completed,@IsPartial,@Partitioned,@IsAutomaticallyGenerated); 
SELECT CollectionId, ParentCollectionId, StartDate, EndDate, Completed, IsPartial, Partitioned, IsAutomaticallyGenerated FROM AnpCollection WHERE (CollectionId = SCOPE_IDENTITY()) 

但是,如果我這樣做,而不是被更新的列,新行會出現與正確的標識值......這不是我想要的......有人能幫助我嗎?提前致謝!

回答

1

離開INSERT聲明與SELECT末,它似乎是一個正確的代碼這裏是:的

anpCollectionTableAdapter.Update(anpDatabase.AnpCollection); 

代替:

var changes = anpDatabase.AnpCollection.GetChanges(); 
anpCollectionTableAdapter.Update((AnpDatabase.AnpCollectionDataTable)changes); 
anpDatabase.AnpCollection.Merge(changes); 
anpDatabase.AnpCollection.AcceptChanges(); 
+0

這就是它!謝謝!! –