System.Data.DataRow.this C# (CSharp) Method

this() public method

Gets or sets the data stored in the specified .
public this ( DataColumn column ) : object
column DataColumn
return object
        public object this[DataColumn column]
        {
            get
            {
                CheckColumn(column);
                int record = GetDefaultRecord();
                _table._recordManager.VerifyRecord(record, this);
                VerifyValueFromStorage(column, DataRowVersion.Default, column[record]);
                return column[record];
            }
            set
            {
                CheckColumn(column);
                if (_inChangingEvent)
                {
                    throw ExceptionBuilder.EditInRowChanging();
                }
                if ((-1 != rowID) && column.ReadOnly)
                {
                    throw ExceptionBuilder.ReadOnly(column.ColumnName);
                }

                // allow users to tailor the proposed value, or throw an exception.
                // note we intentionally do not try/catch this event.
                // note: we also allow user to do anything at this point
                // infinite loops are possible if user calls Item or ItemArray during the event
                DataColumnChangeEventArgs e = null;
                if (_table.NeedColumnChangeEvents)
                {
                    e = new DataColumnChangeEventArgs(this, column, value);
                    _table.OnColumnChanging(e);
                }

                if (column.Table != _table)
                {
                    // user removed column from table during OnColumnChanging event
                    throw ExceptionBuilder.ColumnNotInTheTable(column.ColumnName, _table.TableName);
                }
                if ((-1 != rowID) && column.ReadOnly)
                {
                    // user adds row to table during OnColumnChanging event
                    throw ExceptionBuilder.ReadOnly(column.ColumnName);
                }

                object proposed = ((null != e) ? e.ProposedValue : value);
                if (null == proposed)
                {
                    if (column.IsValueType)
                    {
                        throw ExceptionBuilder.CannotSetToNull(column);
                    }
                    proposed = DBNull.Value;
                }

                bool immediate = BeginEditInternal();
                try
                {
                    int record = GetProposedRecordNo();
                    _table._recordManager.VerifyRecord(record, this);
                    column[record] = proposed;
                }
                catch (Exception e1) when (Common.ADP.IsCatchableOrSecurityExceptionType(e1))
                {
                    if (immediate)
                    {
                        Debug.Assert(!_inChangingEvent, "how are we in a changing event to cancel?");
                        Debug.Assert(-1 != _tempRecord, "how no propsed record to cancel?");
                        CancelEdit();
                    }
                    throw;
                }
                LastChangedColumn = column;

                // note: we intentionally do not try/catch this event.
                // infinite loops are possible if user calls Item or ItemArray during the event
                if (null != e)
                {
                    _table.OnColumnChanged(e); // user may call CancelEdit or EndEdit
                }

                if (immediate)
                {
                    Debug.Assert(!_inChangingEvent, "how are we in a changing event to end?");
                    EndEdit();
                }
            }
        }

Same methods

DataRow::this ( DataColumn column, DataRowVersion version ) : object
DataRow::this ( int columnIndex ) : object
DataRow::this ( int columnIndex, DataRowVersion version ) : object
DataRow::this ( string columnName ) : object
DataRow::this ( string columnName, DataRowVersion version ) : object