Exemple #1
0
        /// <summary>
        /// Returns a <see cref="T:System.Data.DataTable"/> that describes the column metadata of the <see cref="T:System.Data.IDataReader"/>.
        /// </summary>
        /// <returns>
        /// A <see cref="T:System.Data.DataTable"/> that describes the column metadata.
        /// </returns>
        /// <exception cref="T:System.InvalidOperationException">The <see cref="T:System.Data.IDataReader"/> is closed. </exception>
        public virtual System.Data.DataTable GetSchemaTable()
        {
            System.Data.DataTable schemaTable = new System.Data.DataTable();

            schemaTable.Columns.Add("ColumnName", typeof(String));
            schemaTable.Columns.Add("ColumnOrdinal", typeof(Int32));
            schemaTable.Columns.Add("ColumnSize", typeof(Int32));
            schemaTable.Columns.Add("NumericPrecision", typeof(Int32));
            schemaTable.Columns.Add("NumericScale", typeof(Int32));
            schemaTable.Columns.Add("IsUnique", typeof(Boolean));
            schemaTable.Columns.Add("IsKey", typeof(Boolean));
            schemaTable.Columns.Add("BaseCatalogName", typeof(String));
            schemaTable.Columns.Add("BaseColumnName", typeof(String));
            schemaTable.Columns.Add("BaseSchemaName", typeof(String));
            schemaTable.Columns.Add("BaseTableName", typeof(String));
            schemaTable.Columns.Add("DataType", typeof(Type));
            schemaTable.Columns.Add("AllowDBNull", typeof(Boolean));
            schemaTable.Columns.Add("ProviderType", typeof(Int32));
            schemaTable.Columns.Add("IsAliased", typeof(Boolean));
            schemaTable.Columns.Add("IsExpression", typeof(Boolean));
            schemaTable.Columns.Add("IsIdentity", typeof(Boolean));
            schemaTable.Columns.Add("IsAutoIncrement", typeof(Boolean));
            schemaTable.Columns.Add("IsRowVersion", typeof(Boolean));
            schemaTable.Columns.Add("IsHidden", typeof(Boolean));
            schemaTable.Columns.Add("IsLong", typeof(Boolean));
            schemaTable.Columns.Add("IsReadOnly", typeof(Boolean));

            schemaTable.BeginLoadData();
            for (int i = 0; i < this.FieldCount; i++)
            {
                System.Data.DataRow schemaRow = schemaTable.NewRow();

                schemaRow["ColumnName"]       = GetName(i);
                schemaRow["ColumnOrdinal"]    = i;
                schemaRow["ColumnSize"]       = -1;
                schemaRow["NumericPrecision"] = 0;
                schemaRow["NumericScale"]     = 0;
                schemaRow["IsUnique"]         = false;
                schemaRow["IsKey"]            = false;
                schemaRow["BaseCatalogName"]  = "";
                schemaRow["BaseColumnName"]   = GetName(i);
                schemaRow["BaseSchemaName"]   = "";
                schemaRow["BaseTableName"]    = "";
                schemaRow["DataType"]         = GetFieldType(i);
                schemaRow["AllowDBNull"]      = true;
                schemaRow["ProviderType"]     = 0;
                schemaRow["IsAliased"]        = false;
                schemaRow["IsExpression"]     = false;
                schemaRow["IsIdentity"]       = false;
                schemaRow["IsAutoIncrement"]  = false;
                schemaRow["IsRowVersion"]     = false;
                schemaRow["IsHidden"]         = false;
                schemaRow["IsLong"]           = false;
                schemaRow["IsReadOnly"]       = false;

                schemaTable.Rows.Add(schemaRow);
                schemaRow.AcceptChanges();
            }
            schemaTable.EndLoadData();

            return(schemaTable);
        }