System.Data.DataColumn.SetTable C# (CSharp) Method

SetTable() private method

Internal mechanism for changing the table pointer.
private SetTable ( DataTable table ) : void
table DataTable
return void
        internal void SetTable(DataTable table)
        {
            if (_table != table)
            {
                if (Computed)
                {
                    if ((table == null) || (!table.fInitInProgress && ((table.DataSet == null) || (!table.DataSet._fIsSchemaLoading && !table.DataSet._fInitInProgress))))
                    {
                        // We need to re-bind all expression columns.
                        DataExpression.Bind(table);
                    }
                }

                if (Unique && _table != null)
                {
                    UniqueConstraint constraint = table.Constraints.FindKeyConstraint(this);
                    if (constraint != null)
                    {
                        table.Constraints.CanRemove(constraint, true);
                    }
                }
                _table = table;
                _storage = null; // empty out storage for reuse.
            }
        }

Usage Example

Exemplo n.º 1
0
        /// <devdoc>
        /// Does verification on the column and it's name, and points the column at the dataSet that owns this collection.
        /// An ArgumentNullException is thrown if this column is null.  An ArgumentException is thrown if this column
        /// already belongs to this collection, belongs to another collection.
        /// A DuplicateNameException is thrown if this collection already has a column with the same
        /// name (case insensitive).
        /// </devdoc>
        private void BaseAdd(DataColumn column)
        {
            if (column == null)
            {
                throw ExceptionBuilder.ArgumentNull("column");
            }
            if (column.table == table)
            {
                throw ExceptionBuilder.CannotAddColumn1(column.ColumnName);
            }
            if (column.table != null)
            {
                throw ExceptionBuilder.CannotAddColumn2(column.ColumnName);
            }

            if (column.ColumnName.Length == 0)
            {
                column.ColumnName = AssignName();
            }
            RegisterColumnName(column.ColumnName, column);
            try {
                column.SetTable(table);
                if (!table.fInitInProgress && column.Computed)
                {
                    if (column.DataExpression.DependsOn(column))
                    {
                        throw ExceptionBuilder.ExpressionCircular();
                    }
                }

                if (0 < table.RecordCapacity)
                {
                    // adding a column to table with existing rows
                    column.SetCapacity(table.RecordCapacity);
                }

                // fill column with default value.
                for (int record = 0; record < table.RecordCapacity; record++)
                {
                    column.InitializeRecord(record);
                }

                if (table.DataSet != null)
                {
                    column.OnSetDataSet();
                }
            }
            catch (Exception e) {
                //
                if (ADP.IsCatchableOrSecurityExceptionType(e))
                {
                    UnregisterName(column.ColumnName);
                }
                throw;
            }
        }
All Usage Examples Of System.Data.DataColumn::SetTable