System.Data.IDataAdapter.FillSchema Method

Adds a System.Data.DataTable named "Table" to the specified System.Data.DataSet and configures the schema to match that in the data source based on the specified System.Data.SchemaType.

Syntax

public DataTable[] FillSchema (DataSet dataSet, SchemaType schemaType)

Parameters

dataSet
The System.Data.DataSet to be filled with the schema from the data source.
schemaType
One of the System.Data.SchemaType values.

Returns

An array of System.Data.DataTable objects that contain schema information returned from the data source.

Remarks

The IDataAdapter.FillSchema(DataSet, SchemaType) method retrieves the schema from the data source using the IDbDataAdapter.SelectCommand. The connection object associated with the IDbDataAdapter.SelectCommand must be valid, but it does not need to be open. If the connection is closed before IDataAdapter.FillSchema(DataSet, SchemaType) is called, it is opened to retrieve data, then closed. If the connection is open before IDataAdapter.FillSchema(DataSet, SchemaType) is called, it remains open.

A IDataAdapter.FillSchema(DataSet, 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:

IDataAdapter.FillSchema(DataSet, SchemaType) also configures the DataTable.PrimaryKey and DataTable.Constraints properties according to the following rules:

Note that primary keys and unique constraints are added to the System.Data.ConstraintCollection according to the previous 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 how to specify query hints, see tp://msdn.microsoft.com/library/ms181714.aspx.

If the System.Data.IDataAdapter encounters duplicate columns while populating a System.Data.DataTable, it generates names for the successive columns, using the pattern "columnname1", "columnname2", "columnname3", and so on. If the incoming data contains unnamed columns, they are put 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 put 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 should use caution when using column and table names to ensure that conflicts with these naming patterns do not occur.

IDataAdapter.FillSchema(DataSet, SchemaType) returns no rows. Use the IDataAdapter.Fill(DataSet) method to add rows to a System.Data.DataTable.

Requirements

Namespace: System.Data
Assembly: System.Data (in System.Data.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0