有DataTable.Clear和DataTable.Rows.Clear有区别吗? [英] Is there a difference between DataTable.Clear and DataTable.Rows.Clear?

查看:1097
本文介绍了有DataTable.Clear和DataTable.Rows.Clear有区别吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我记得有直接呼吁的数据表类,并在 DataTable.Rows 财产。 (也许已经是行数/计数这是我读到这个属性。)不同的是其中一人忽略的 DataRow.RowState 和其它方面/使用它

I recall there is a difference between some methods/properties called directly on the DataTable class, and the identically named methods/properties on the DataTable.Rows property. (Might have been the RowCount/Count property for which I read this.) The difference is one of them disregards DataRow.RowState, and the other respects/uses it.

在这种特殊情况下,我想知道的 DataTable.Clear 和的 DataTable.Rows.Clear 。我能想象他们中的一个实际删除所有行,而另一只将其标记为删除。

In this particular case I'm wondering about the difference between DataTable.Clear and DataTable.Rows.Clear. I can imagine one of them actually removes all rows, and the other one just marks them as deleted.

所以我的问题是,有两种清除方法之间的差异,如果有什么区别?

(呵呵,这是.NET 1.1顺便说一句,如果语义从一个版本到另一个变化。)

(Oh, this is for .NET 1.1 btw, in case the semantics changed from one version to another.)

推荐答案

在.NET 1.1中, DataRowCollection.Clear 电话 DataTable.Clear

In .Net 1.1, DataRowCollection.Clear calls DataTable.Clear

不过,.NET 2.0中,是有区别的。 如果我没有理解错误的来源, DataTable.Clear 将清除独立的行(使用创建 DataTable.NewRow ),而DataRowCollection。清除不会。

However, in .Net 2.0, there is a difference. If I understand the source correctly, DataTable.Clear will clear unattached rows (created using DataTable.NewRow) whereas DataRowCollection.Clear won't.

所不同的是在 RecordManager.Clear (来源下方,从。净参考源为V3.5 SP 0); clearAll 是真实的 DataTable.Clear 只调用时。

The difference is in RecordManager.Clear (source below, from the .Net Reference Source for v3.5 SP 0); clearAll is true only when called from DataTable.Clear.

    internal void Clear(bool clearAll) { 
        if (clearAll) {
            for(int record = 0; record < recordCapacity; ++record) { 
                rows[record] = null;
            }
            int count = table.columnCollection.Count;
            for(int i = 0; i < count; ++i) { 
                //

                DataColumn column = table.columnCollection[i]; 
                for(int record = 0; record < recordCapacity; ++record) {
                    column.FreeRecord(record); 
                }
            }
            lastFreeRecord = 0;
            freeRecordList.Clear(); 
        }
        else { // just clear attached rows 
            freeRecordList.Capacity = freeRecordList.Count + table.Rows.Count; 
            for(int record = 0; record < recordCapacity; ++record) {
                if (rows[record]!= null && rows[record].rowID != -1) { 
                    int tempRecord = record;
                    FreeRecord(ref tempRecord);
                }
            } 
        }
    }

这篇关于有DataTable.Clear和DataTable.Rows.Clear有区别吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆