关于微软有自增列父子表更新程序的问题

本文探讨了在.NET框架中处理SQLRowUpdatedEventArgs时的具体细节,特别是如何使用UpdateStatus.SkipCurrentRow来阻止某些更改,并解释了为何在设置SkipCurrentRow之后还需要调用AcceptChanges()方法。

有一些不明白它的意思.请高手详细说明一下原由.谢谢!
来源网址: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; // 这里也不明白它的用意.

 

转载于:https://www.cnblogs.com/tonyepaper/archive/2009/10/22/1587764.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值