Argentini.Halide.DatabaseRow.AddColumn C# (CSharp) Method

AddColumn() public method

Add a column to the data set in memory. This is useful when stored procedures used for saving data require optional parameters.

The new column will act just like a real SQL data column, and you may want to add a faux SQL data type to its properties, as well as any other properties, so that you can manipulate it properly.

public AddColumn ( String colName, String colValue ) : System.Boolean
colName String Name of the new column.
colValue String Value of the new column.
return System.Boolean
        public Boolean AddColumn(String colName, String colValue)
        {
            bool retVal = false;
            int oldFieldCount = _fieldCount;
            String newVal = colValue;
            String columnName = colName.ToLower();

            if (String.IsNullOrEmpty(newVal))
                newVal = "";

            if (!String.IsNullOrEmpty(columnName))
            {
                try
                {
                    #region COPY DATA INTO NEW ARRAY, ONE LARGER THAN CURRENT

                    DatabaseItem[] _dataItemsX;
                    _dataItemsX = new DatabaseItem[_fieldCount + 1];

                    for (int x = 0; x < _fieldCount; x++)
                    {
                        _dataItemsX[x] = new DatabaseItem();
                        _dataItemsX[x] = _dataItems[x];
                    }

                    #endregion

                    #region ADD NEW ENTRY TO END OF NEW ARRAY

                    _dataItemsX[_fieldCount] = new DatabaseItem();
                    _dataItemsX[_fieldCount].ColumnName = columnName;
                    _dataItemsX[_fieldCount].Value = newVal;
                    _dataItemsX[_fieldCount].ColumnSize = 0;
                    _dataItemsX[_fieldCount].ColumnSQLType = "";
                    _dataItemsX[_fieldCount].IsAutoIncrementing = false;
                    _dataItemsX[_fieldCount].IsIdentity = false;
                    _dataItemsX[_fieldCount].IsNullable = false;
                    _dataItemsX[_fieldCount].IsPrimaryKey = false;
                    _dataItemsX[_fieldCount].SystemDataType = "";

                    _dataIndex.Add(columnName, _fieldCount);
                    _fieldCount++;

                    #endregion

                    #region ENLARGE OLD ARRAY; COPY NEW ARRAY BACK INTO OLD ONE

                    _dataItems = new DatabaseItem[_fieldCount];

                    for (int x = 0; x < _fieldCount; x++)
                    {
                        _dataItems[x] = new DatabaseItem();
                        _dataItems[x] = _dataItemsX[x];
                    }

                    #endregion

                    retVal = true;
                }

                catch
                {
                    _fieldCount = oldFieldCount;
                }
            }

            return retVal;
        }