Beispiel #1
0
        /// <include file='doc\DataRow.uex' path='docs/doc[@for="DataRow.this2"]/*' />
        /// <devdoc>
        ///    <para>Gets or sets
        ///       the data stored in the specified <see cref='System.Data.DataColumn'/>.</para>
        /// </devdoc>
        public object this[DataColumn column] {
            get {
                return(this[column, DataRowVersion.Default]);
            }
            set {
                CheckColumn(column);

#if DEBUG
                if (CompModSwitches.Data_ColumnChange.TraceVerbose)
                {
                    Debug.WriteLine("Data_ColumnDataChange - rowID: " + (rowID) + ", columnName: " + column.ColumnName + ", value: <" + Convert.ToString(value) + ">");
                }
#endif
                if (inChangingEvent)
                {
                    throw ExceptionBuilder.EditInRowChanging();
                }

                // allow users to tailor the proposed value, or throw an exception.
                // note we intentionally do not try/catch this event.
                DataColumnChangeEventArgs e = new DataColumnChangeEventArgs(this, column, value);
                Table.RaiseColumnChanging(this, e);

                // Check null
                if (e.ProposedValue == null && column.DataType != typeof(String))
                {
                    throw ExceptionBuilder.CannotSetToNull(column);
                }

                bool immediate = (tempRecord == -1);
                if (immediate)
                {
                    BeginEdit(); // for now force the update.  let's try to improve this later.
                }
                column[GetProposedRecordNo()] = e.ProposedValue;
                Table.RaiseColumnChanged(this, e);

                if (immediate)
                {
                    EndEdit();
                }
            }
        }
Beispiel #2
0
 public object this[DataColumn column]
 {
     get
     {
         this.CheckColumn(column);
         int defaultRecord = this.GetDefaultRecord();
         return(column[defaultRecord]);
     }
     set
     {
         this.CheckColumn(column);
         if (this.inChangingEvent)
         {
             throw ExceptionBuilder.EditInRowChanging();
         }
         if ((-1L != this.rowID) && column.ReadOnly)
         {
             throw ExceptionBuilder.ReadOnly(column.ColumnName);
         }
         DataColumnChangeEventArgs e = null;
         if (this._table.NeedColumnChangeEvents)
         {
             e = new DataColumnChangeEventArgs(this, column, value);
             this._table.OnColumnChanging(e);
         }
         if (column.Table != this._table)
         {
             throw ExceptionBuilder.ColumnNotInTheTable(column.ColumnName, this._table.TableName);
         }
         if ((-1L != this.rowID) && column.ReadOnly)
         {
             throw ExceptionBuilder.ReadOnly(column.ColumnName);
         }
         object obj2 = (e != null) ? e.ProposedValue : value;
         if (obj2 == null)
         {
             if (column.IsValueType)
             {
                 throw ExceptionBuilder.CannotSetToNull(column);
             }
             obj2 = DBNull.Value;
         }
         bool flag = this.BeginEditInternal();
         try
         {
             int proposedRecordNo = this.GetProposedRecordNo();
             column[proposedRecordNo] = obj2;
         }
         catch (Exception exception)
         {
             if (ADP.IsCatchableOrSecurityExceptionType(exception) && flag)
             {
                 this.CancelEdit();
             }
             throw;
         }
         this.LastChangedColumn = column;
         if (e != null)
         {
             this._table.OnColumnChanged(e);
         }
         if (flag)
         {
             this.EndEdit();
         }
     }
 }