有一些不明白它的意思.請高手詳細說明一下原由.謝謝!
來源網址:http://support.microsoft.com/?scid=kb%3Bzh-cn%3B320301&x=11&y=15
protected static void OnDetailsRowUpdated(object sender, SqlRowUpdatedEventArgs args)
{
if(args.StatementType == StatementType.Insert )
{
// Do not allow the AcceptChanges to occur on this row.
args.Status = UpdateStatus.SkipCurrentRow;//這裡為什麼要用UpdateStatus.SkipCurrentRow
// Get the current, actual primary key value so that you can plug it back
// in after you get the correct original value that was generated for the child row.
int currentkey = (int)args.Row["OrderID"];
// This is where you get a correct original value key that is stored to the child row.
// You pull the original, pseudo key value from the parent, plug it in as the child row's primary key
// field, and then accept changes on it. Specifically, this is why you turned off EnforceConstraints.
args.Row["OrderID"] = args.Row.GetParentRow("OrdDetail")["OrderID",DataRowVersion.Original];
args.Row.AcceptChanges();//上面用了UpdateStatus.SkipCurrentRow,這裡為什麼還要AcceptChanges(),感覺矛盾.
// Store the actual primary key value in the foreign key column of the child row.
args.Row["OrderID"] = currentkey;//為什麼又改回原來的值???
}
if(args.StatementType == StatementType.Delete )
args.Status = UpdateStatus.SkipCurrentRow;//這裡也不明白它的用意.