A System.Data.DataTable object that contains schema information returned from the data source.
The DataAdapter.FillSchema(System.Data.DataSet, System.Data.SchemaType) method retrieves the schema from the data source using the System.Data.IDbDataAdapter.SelectCommand. The connection object associated with the System.Data.IDbDataAdapter.SelectCommand must be valid, but it does not need to be open. If the connection is closed before DataAdapter.FillSchema(System.Data.DataSet, System.Data.SchemaType) is called, it is opened to retrieve data and then closed. If the connection is open before DataAdapter.FillSchema(System.Data.DataSet, System.Data.SchemaType) is called, it remains open.
A DataAdapter.FillSchema(System.Data.DataSet, System.Data.SchemaType) operation adds a System.Data.DataTable to the destination System.Data.DataSet. It then adds columns to the System.Data.DataColumnCollection of the System.Data.DataTable, and configures the following System.Data.DataColumn properties if they exist at the data source:
DataAdapter.FillSchema(System.Data.DataSet, System.Data.SchemaType) also configures the System.Data.DataTable.PrimaryKey and System.Data.DataTable.Constraints properties according to the following rules:
If no primary key columns are returned but unique columns are, the unique columns are used as the primary key if, and only if, all the unique columns are nonnullable. If any of the columns are nullable, a System.Data.UniqueConstraint is added to the System.Data.ConstraintCollection, but the System.Data.DataTable.PrimaryKey property is not set.
If both primary key columns and unique columns are returned, the primary key columns are used as the primary key columns for the System.Data.DataTable.
The underlying data store may allow column attributes that are not supported in a System.Data.DataColumn, which causes some column attributes to not translate correctly. For example, ssNoVersion allows an identity column with a data type of tinyint whereas a System.Data.DataColumn only allows Int16, Int32, and Int64 to have the System.Data.DataColumn.AutoIncrement property set. FillSchema silently ignores cases where the System.Data.DataColumn cannot accurately mirror the data source and throws no exception.
Note that primary keys and unique constraints are added to the System.Data.ConstraintCollection according to the preceding rules, but other constraint types are not added.
If a unique clustered index is defined on a column or columns in a SQL Server table and the primary key constraint is defined on a separate set of columns, then the names of the columns in the clustered index will be returned. To return the name or names of the primary key columns, use a query hint with the SELECT statement that specifies the name of the primary key index. For more information about specifying query hints, see tp://msdn.microsoft.com/library/ms181714.aspx.
If the System.Data.Common.DataAdapter encounters duplicate columns while populating a System.Data.DataTable, it generates names for the subsequent columns, using the pattern "columnname1", "columnname2", "columnname3", and so on. If the incoming data contains unnamed columns, they are placed in the System.Data.DataSet according to the pattern "Column1", "Column2", and so on. When multiple result sets are added to the System.Data.DataSet each result set is placed in a separate table. Additional result sets are named by appending integral values to the specified table name (for example, "Table", "Table1", "Table2", and so on). Applications using column and table names should ensure that conflicts with these naming patterns does not occur.
DataAdapter.FillSchema(System.Data.DataSet, System.Data.SchemaType) does not return any rows. Use the DataAdapter.Fill(System.Data.DataSet) method to add rows to a System.Data.DataTable.
When handling batch SQL statements that return multiple results, the implementation of DbDataAdapter.FillSchema(System.Data.DataTable, System.Data.SchemaType) for the .NET Framework Data Provider for OLE DB retrieves schema information for only the first result. To retrieve schema information for multiple results, use DbDataAdapter.Fill(System.Data.DataSet) with the System.Data.MissingSchemaAction set to AddWithKey.