Exemple #1
0
        /// <summary>
        ///     Converts the specified TableMetadata's fields into a DataTable.
        /// </summary>
        /// <param name="data">TableMetadata array from which the conversion is made</param>
        /// <param name="fields">List of fields to be included</param>
        /// <returns>Resulting DataTable</returns>
        public DataTable ConvertToDataTable(TableMetadata[] data, params DatabaseField[] fields)
        {
            DataTable table = new DataTable();

            DataFactory factory = new DataFactory();

            for (int i = 0; i < fields.Length; i++)
            {
                DataColumn column = new DataColumn(fields[i].fieldName, factory.InitializeDataType(fields[i].fieldType));
                column.AutoIncrement = fields[i].isValueAutogenerated;
                column.AllowDBNull   = true;
                table.Columns.Add(column);
            }

            for (int i = 0; i < data.Length; i++)
            {
                DataRow drow = table.NewRow();

                for (int j = 0; j < fields.Length; j++)
                {
                    drow[j] = data[i].TableFields[j].fieldValue;
                }

                table.Rows.Add(drow);
            }

            return(table);
        }