關於微軟有自增列父子表更新程式的問題

來源:互聯網
上載者:User

有一些不明白它的意思.請高手詳細說明一下原由.謝謝!
來源網址: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;//這裡也不明白它的用意.

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.