SetTable() private method

Internal mechanism for changing the table pointer.
private SetTable ( DataTable table ) : void
table DataTable
return void
        /// <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;
            }
        }
 private void BaseRemove(DataColumn column)
 {
     if (this.CanRemove(column, true))
     {
         if (column.errors > 0)
         {
             for (int i = 0; i < this.table.Rows.Count; i++)
             {
                 this.table.Rows[i].ClearError(column);
             }
         }
         this.UnregisterName(column.ColumnName);
         column.SetTable(null);
     }
 }
 private void BaseAdd(DataColumn column)
 {
     if (column == null)
     {
         throw ExceptionBuilder.ArgumentNull("column");
     }
     if (column.table == this.table)
     {
         throw ExceptionBuilder.CannotAddColumn1(column.ColumnName);
     }
     if (column.table != null)
     {
         throw ExceptionBuilder.CannotAddColumn2(column.ColumnName);
     }
     if (column.ColumnName.Length == 0)
     {
         column.ColumnName = this.AssignName();
     }
     this.RegisterColumnName(column.ColumnName, column, null);
     try
     {
         column.SetTable(this.table);
         if ((!this.table.fInitInProgress && column.Computed) && column.DataExpression.DependsOn(column))
         {
             throw ExceptionBuilder.ExpressionCircular();
         }
         if (0 < this.table.RecordCapacity)
         {
             column.SetCapacity(this.table.RecordCapacity);
         }
         for (int i = 0; i < this.table.RecordCapacity; i++)
         {
             column.InitializeRecord(i);
         }
         if (this.table.DataSet != null)
         {
             column.OnSetDataSet();
         }
     }
     catch (Exception exception)
     {
         if (ADP.IsCatchableOrSecurityExceptionType(exception))
         {
             this.UnregisterName(column.ColumnName);
         }
         throw;
     }
 }
Example #4
0
 /// <summary>
 /// Does verification on the column and it's name, and clears the column's dataSet pointer.
 /// An ArgumentNullException is thrown if this column is null.  An ArgumentException is thrown
 /// if this column doesn't belong to this collection or if this column is part of a relationship.
 /// An ArgumentException is thrown if another column's compute expression depends on this column.
 /// </summary>
 private void BaseRemove(DataColumn column)
 {
     if (CanRemove(column, true))
     {
         // remove
         if (column._errors > 0)
         {
             for (int i = 0; i < _table.Rows.Count; i++)
             {
                 _table.Rows[i].ClearError(column);
             }
         }
         UnregisterName(column.ColumnName);
         column.SetTable(null);
     }
 }
Example #5
0
        /// <include file='doc\DataColumnCollection.uex' path='docs/doc[@for="DataColumnCollection.BaseAdd"]/*' />
        /// <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, DataStorage storage)
        {
            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);
            }

            // this will bind the expression.
            column.SetTable(table);
            // bind the storage here (SetTable above will set it to null)
            column.Storage = storage;

            if (column.ColumnName.Length == 0)
            {
                column.ColumnName = AssignName();
            }
            else
            {
                RegisterName(column.ColumnName, column);
            }
            column.hashCode = GetSpecialHashCode(column.ColumnName);

            if (table.RecordCapacity > 0)
            {
                column.SetCapacity(table.RecordCapacity);
            }

            // fill column with default value.
            for (int i = 0; i < table.RecordCapacity; i++)
            {
                column[i] = column.DefaultValue;
            }

            if (table.DataSet != null)
            {
                column.OnSetDataSet();
            }
        }
Example #6
0
        /// <summary>
        /// Creates and adds the specified DataColumn object to the DataColumnCollection.
        /// </summary>
        /// <param name="column">The DataColumn to add.</param>
        public void Add(DataColumn column)
        {
            if (column == null)
            {
                throw new ArgumentNullException("column", "'column' argument cannot be null.");
            }

#if !NET_2_0
            /* in 1.1, they must do this here, as the
             * setting of ColumnName below causes an event
             * to be raised */
            column.PropertyChanged += new PropertyChangedEventHandler(ColumnPropertyChanged);
#endif

            if (column.ColumnName.Length == 0)
            {
                column.ColumnName = GetNextDefaultColumnName();
            }

//			if (Contains(column.ColumnName))
//				throw new DuplicateNameException("A DataColumn named '" + column.ColumnName + "' already belongs to this DataTable.");

            if (column.Table != null)
            {
                throw new ArgumentException("Column '" + column.ColumnName + "' already belongs to this or another DataTable.");
            }

            column.SetTable(parentTable);
            RegisterName(column.ColumnName, column);
            int ordinal = base.List.Add(column);

#if NET_2_0
            column.Ordinal = ordinal;
#else
            column.SetOrdinal(ordinal);
#endif

            // Check if the Column Expression is ok
            if (column.CompiledExpression != null)
            {
                if (parentTable.Rows.Count == 0)
                {
                    column.CompiledExpression.Eval(parentTable.NewRow());
                }
                else
                {
                    column.CompiledExpression.Eval(parentTable.Rows[0]);
                }
            }

            // if table already has rows we need to allocate space
            // in the column data container
            if (parentTable.Rows.Count > 0)
            {
                column.DataContainer.Capacity = parentTable.RecordCache.CurrentCapacity;
            }

            if (column.AutoIncrement)
            {
                DataRowCollection rows = column.Table.Rows;
                for (int i = 0; i < rows.Count; i++)
                {
                    rows [i] [ordinal] = column.AutoIncrementValue();
                }
            }

            if (column.AutoIncrement)
            {
                autoIncrement.Add(column);
            }

#if NET_2_0
            column.PropertyChanged += new PropertyChangedEventHandler(ColumnPropertyChanged);
#endif

            OnCollectionChanged(new CollectionChangeEventArgs(CollectionChangeAction.Add, column));
        }
 private void BaseRemove(DataColumn column)
 {
     if (this.CanRemove(column, true))
     {
         if (column.errors > 0)
         {
             for (int i = 0; i < this.table.Rows.Count; i++)
             {
                 this.table.Rows[i].ClearError(column);
             }
         }
         this.UnregisterName(column.ColumnName);
         column.SetTable(null);
     }
 }
 private void BaseAdd(DataColumn column)
 {
     if (column == null)
     {
         throw ExceptionBuilder.ArgumentNull("column");
     }
     if (column.table == this.table)
     {
         throw ExceptionBuilder.CannotAddColumn1(column.ColumnName);
     }
     if (column.table != null)
     {
         throw ExceptionBuilder.CannotAddColumn2(column.ColumnName);
     }
     if (column.ColumnName.Length == 0)
     {
         column.ColumnName = this.AssignName();
     }
     this.RegisterColumnName(column.ColumnName, column, null);
     try
     {
         column.SetTable(this.table);
         if ((!this.table.fInitInProgress && column.Computed) && column.DataExpression.DependsOn(column))
         {
             throw ExceptionBuilder.ExpressionCircular();
         }
         if (0 < this.table.RecordCapacity)
         {
             column.SetCapacity(this.table.RecordCapacity);
         }
         for (int i = 0; i < this.table.RecordCapacity; i++)
         {
             column.InitializeRecord(i);
         }
         if (this.table.DataSet != null)
         {
             column.OnSetDataSet();
         }
     }
     catch (Exception exception)
     {
         if (ADP.IsCatchableOrSecurityExceptionType(exception))
         {
             this.UnregisterName(column.ColumnName);
         }
         throw;
     }
 }
        /// <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;
            }
        }
		/// <summary>
		/// Creates and adds the specified DataColumn object to the DataColumnCollection.
		/// </summary>
		/// <param name="column">The DataColumn to add.</param>
		public void Add(DataColumn column)
		{

			if (column == null)
				throw new ArgumentNullException ("column", "'column' argument cannot be null.");

			if (column.ColumnName.Equals(String.Empty))
			{
				column.ColumnName = GetNextDefaultColumnName ();
			}

//			if (Contains(column.ColumnName))
//				throw new DuplicateNameException("A DataColumn named '" + column.ColumnName + "' already belongs to this DataTable.");

			if (column.Table != null)
				throw new ArgumentException ("Column '" + column.ColumnName + "' already belongs to this or another DataTable.");

			CollectionChangeEventArgs e = new CollectionChangeEventArgs(CollectionChangeAction.Add, this);

			column.SetTable (parentTable);
			RegisterName(column.ColumnName, column);
			int ordinal = base.List.Add(column);
			column.SetOrdinal (ordinal);

			// if table already has rows we need to allocate space 
			// in the column data container 
			if ( parentTable.Rows.Count > 0 ) {
				column.DataContainer.Capacity = parentTable.RecordCache.CurrentCapacity;
			}

			if (column.AutoIncrement) {
				DataRowCollection rows = column.Table.Rows;
				for (int i = 0; i < rows.Count; i++)
					rows [i] [ordinal] = column.AutoIncrementValue ();
			}

			if (column.AutoIncrement)
				autoIncrement.Add(column);

			OnCollectionChanged (e);
		}
		/// <summary>
		/// Creates and adds the specified DataColumn object to the DataColumnCollection.
		/// </summary>
		/// <param name="column">The DataColumn to add.</param>
		public void Add (DataColumn column)
		{
			if (column == null)
				throw new ArgumentNullException ("column", "'column' argument cannot be null.");


			if (column.ColumnName.Length == 0) {
				column.ColumnName = GetNextDefaultColumnName ();
			}

//			if (Contains(column.ColumnName))
//				throw new DuplicateNameException("A DataColumn named '" + column.ColumnName + "' already belongs to this DataTable.");

			if (column.Table != null)
				throw new ArgumentException ("Column '" + column.ColumnName + "' already belongs to this or another DataTable.");

			column.SetTable (parentTable);
			RegisterName (column.ColumnName, column);
			int ordinal = base.List.Add (column);

			column.Ordinal = ordinal;

			// Check if the Column Expression is ok
			if (column.CompiledExpression != null)
				if (parentTable.Rows.Count == 0)
					column.CompiledExpression.Eval (parentTable.NewRow());
				else
					column.CompiledExpression.Eval (parentTable.Rows[0]);

			// if table already has rows we need to allocate space
			// in the column data container
			if (parentTable.Rows.Count > 0)
				column.DataContainer.Capacity = parentTable.RecordCache.CurrentCapacity;

			if (column.AutoIncrement) {
				DataRowCollection rows = column.Table.Rows;
				for (int i = 0; i < rows.Count; i++)
					rows [i] [ordinal] = column.AutoIncrementValue ();
			}

			if (column.AutoIncrement)
				autoIncrement.Add (column);

			column.PropertyChanged += new PropertyChangedEventHandler (ColumnPropertyChanged);

			OnCollectionChanged (new CollectionChangeEventArgs(CollectionChangeAction.Add, column));
		}
Example #12
0
 /// <summary>
 /// Does verification on the column and it's name, and clears the column's dataSet pointer.
 /// An ArgumentNullException is thrown if this column is null.  An ArgumentException is thrown
 /// if this column doesn't belong to this collection or if this column is part of a relationship.
 /// An ArgumentException is thrown if another column's compute expression depends on this column.
 /// </summary>
 private void BaseRemove(DataColumn column)
 {
     if (CanRemove(column, true))
     {
         // remove
         if (column._errors > 0)
         {
             for (int i = 0; i < _table.Rows.Count; i++)
             {
                 _table.Rows[i].ClearError(column);
             }
         }
         UnregisterName(column.ColumnName);
         column.SetTable(null);
     }
 }