Esempio n. 1
0
        /// <summary>
        ///    This sub creates a given <see cref="DASDataTable"></see> object with the schema information found for the given
        ///    table.
        /// </summary>
        /// <param name="columnList">String with a comma separated list of all columns.</param>
        /// <param name="tableName">Name of the database table which schema should be used.</param>
        /// <exception cref="ArgumentNullException"></exception>
        /// <remarks>
        ///    <para>
        ///       You can use the column list to select the needed columns. You can also rename the database column by using
        ///       aliases in the list.
        ///    </para>
        ///    <para>
        ///       To use aliases just name them like in normal sql. For example
        ///       <quote>column1 as mycolumn1, column2 as mycolumn2</quote>.
        ///    </para>
        /// </remarks>
        /// <exception cref="NotConnectedException">Thrown when there is no established connection.</exception>
        public DASDataTable CreateDASDataTable(string columnList, string tableName)
        {
            if ((string.IsNullOrEmpty(columnList)))
            {
                throw new ArgumentNullException(nameof(columnList));
            }

            if ((string.IsNullOrEmpty(tableName)))
            {
                throw new ArgumentNullException(nameof(tableName));
            }

            if (IsConnected)
            {
                var dataTable = new DASDataTable(this);

                var cmd = _providerFactory.CreateCommand();
                cmd.CommandText = $"SELECT {columnList} FROM {tableName}";
                cmd.Connection  = Connection;
                cmd.Transaction = _transaction;
                dataTable.Load(cmd.ExecuteReader(CommandBehavior.SchemaOnly));

                var dasDataTable = new DASDataTable(this);
                foreach (DataColumn column in dataTable.Columns)
                {
                    var dasColumn = new DASDataColumn
                    {
                        ColumnName   = column.ColumnName,
                        DBColumnName = column.ColumnName,
                        DataType     = column.DataType,
                        MaxLength    = column.MaxLength,
                        AllowDBNull  = column.AllowDBNull,
                        Unique       = column.Unique
                    };
                    dasDataTable.Columns.Add(dasColumn);
                }

                var keys = new DASDataColumn[dataTable.PrimaryKey.Length + 1];
                var i    = 0;
                foreach (var column in dataTable.PrimaryKey)
                {
                    keys[i] = dasDataTable.Columns.ItemByName(column.ColumnName);
                    i      += 1;
                }

                dasDataTable.PrimaryKey  = keys;
                dasDataTable.DBTableName = tableName;
                dasDataTable.BuildAndSetBaseSQL();
                return(dasDataTable);
            }

            throw new NotConnectedException();
        }
Esempio n. 2
0
 /// <summary>
 /// This function checks whether a column exists.
 /// </summary>
 /// <param name="Column"><see cref=" DASDataColumn "></see> to be checked.</param>
 /// <returns><c>True</c>, if column is part of the columns collection.</returns>
 public bool ContainsColumn(DASDataColumn Column)
 {
     return(m_Columns.Contains(Column.ColumnName));
 }
Esempio n. 3
0
 /// <summary>
 /// This sub adds the given column to the collection.
 /// </summary>
 /// <param name="Column"><see cref=" DASDataColumn "></see> object to be added.</param>
 public void Add(DASDataColumn Column)
 {
     m_Columns.Add(Column);
 }
Esempio n. 4
0
 /// <summary>
 /// This sub removes the given column from the collection.
 /// </summary>
 /// <param name="Column"><see cref=" DASDataColumn "></see> object to be removed.</param>
 public void Remove(DASDataColumn Column)
 {
     m_Columns.Remove(Column);
 }
Esempio n. 5
0
 /// <summary>
 /// This is the constructor of the class.
 /// </summary>
 /// <param name="Row"><see cref=" DASDataRow "></see> object needed for initialization.</param>
 /// <param name="Column"><see cref=" DASDataColumn "></see> object needed for initialization.</param>
 public DASColumnValue(DASDataRow Row, DASDataColumn Column)
 {
     _row    = Row;
     _column = Column;
 }