System.Data.DataTableCollection.Clear C# (CSharp) Method

Clear() public method

Clears the collection of any tables.
public Clear ( ) : void
return void
        public void Clear()
        {
            long logScopeId = DataCommonEventSource.Log.EnterScope("<ds.DataTableCollection.Clear|API> {0}", ObjectID);
            try
            {
                int oldLength = _list.Count;
                DataTable[] tables = new DataTable[_list.Count];
                _list.CopyTo(tables, 0);

                OnCollectionChanging(s_refreshEventArgs);

                if (_dataSet._fInitInProgress && _delayedAddRangeTables != null)
                {
                    _delayedAddRangeTables = null;
                }

                BaseGroupSwitch(tables, oldLength, null, 0);
                _list.Clear();

                OnCollectionChanged(s_refreshEventArgs);
            }
            finally
            {
                DataCommonEventSource.Log.ExitScope(logScopeId);
            }
        }

Usage Example

示例#1
0
        public virtual void Reset()
        {
            // first we remove all ForeignKeyConstraints (if we will not do that
            // we will get an exception when clearing the tables).
            for (int i = 0; i < Tables.Count; i++)
            {
                ConstraintCollection cc = Tables[i].Constraints;
                for (int j = 0; j < cc.Count; j++)
                {
                    if (cc[j] is ForeignKeyConstraint)
                    {
                        cc.Remove(cc[j]);
                    }
                }
            }

            Clear();
            Relations.Clear();
            Tables.Clear();
        }