Szerkesztés

Megosztás a következőn keresztül:


DbDataAdapter.FillSchema Method

Definition

Adds a DataTable to a DataSet and configures the schema to match that in the data source.

Overloads

FillSchema(DataSet, SchemaType, IDbCommand, String, CommandBehavior)

Adds a DataTable to the specified DataSet and configures the schema to match that in the data source based on the specified SchemaType.

FillSchema(DataTable, SchemaType, IDbCommand, CommandBehavior)

Configures the schema of the specified DataTable based on the specified SchemaType, command string, and CommandBehavior values.

FillSchema(DataSet, SchemaType, String)

Adds a DataTable to the specified DataSet and configures the schema to match that in the data source based upon the specified SchemaType and DataTable.

FillSchema(DataTable, SchemaType)

Configures the schema of the specified DataTable based on the specified SchemaType.

FillSchema(DataSet, SchemaType)

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

FillSchema(DataSet, SchemaType, IDbCommand, String, CommandBehavior)

Source:
DbDataAdapter.cs
Source:
DbDataAdapter.cs
Source:
DbDataAdapter.cs

Adds a DataTable to the specified DataSet and configures the schema to match that in the data source based on the specified SchemaType.

protected:
 virtual cli::array <System::Data::DataTable ^> ^ FillSchema(System::Data::DataSet ^ dataSet, System::Data::SchemaType schemaType, System::Data::IDbCommand ^ command, System::String ^ srcTable, System::Data::CommandBehavior behavior);
protected virtual System.Data.DataTable[] FillSchema (System.Data.DataSet dataSet, System.Data.SchemaType schemaType, System.Data.IDbCommand command, string srcTable, System.Data.CommandBehavior behavior);
override this.FillSchema : System.Data.DataSet * System.Data.SchemaType * System.Data.IDbCommand * string * System.Data.CommandBehavior -> System.Data.DataTable[]
Protected Overridable Function FillSchema (dataSet As DataSet, schemaType As SchemaType, command As IDbCommand, srcTable As String, behavior As CommandBehavior) As DataTable()

Parameters

dataSet
DataSet

The DataSet to be filled with the schema from the data source.

schemaType
SchemaType

One of the SchemaType values.

command
IDbCommand

The SQL SELECT statement used to retrieve rows from the data source.

srcTable
String

The name of the source table to use for table mapping.

behavior
CommandBehavior

One of the CommandBehavior values.

Returns

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

Remarks

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

A FillSchema operation adds a DataTable to the destination DataSet. It then adds columns to the DataColumnCollection of the DataTable, and configures the following DataColumn properties if they exist at the data source:

FillSchema also configures the PrimaryKey and Constraints properties according to the following rules:

  • If one or more primary key columns are returned by the SelectCommand, they are used as the primary key columns for the DataTable.

  • 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 UniqueConstraint is added to the ConstraintCollection, but the 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 DataTable.

Note that primary keys and unique constraints are added to the 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 Hints (Transact-SQL) - Query.

If the IDataAdapter encounters duplicate columns while populating a 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 DataSet according to the pattern "Column1", "Column2", and so on. When multiple result sets are added to the 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.). If your app uses column and table names, ensure there are no conflicts with these naming patterns.

The FillSchema method supports scenarios where the DataSet contains multiple DataTable objects whose names differ only by case. In such situations, FillSchema performs a case-sensitive comparison to find the corresponding table, and creates a new table if no exact match exists. The following C# code illustrates this behavior.

DataSet dataset = new DataSet();  
dataset.Tables.Add("aaa");  
dataset.Tables.Add("AAA");  
adapter.FillSchema(dataset, "aaa"); // Fills the schema of "aaa", which already exists in the DataSet.  
adapter.FillSchema(dataset, "Aaa"); // Adds a new table called "Aaa".  

If FillSchema is called and the DataSet contains only one DataTable whose name differs only by case, that DataTable is updated. In this scenario, the comparison is case insensitive. The following C# code illustrates this behavior.

DataSet dataset = new DataSet();  
dataset.Tables.Add("aaa");  
adapter.FillSchema(dataset, "AAA"); // Fills the schema of table "aaa" because only one similarly named table is in the DataSet.  

FillSchema does not return any rows. Use the Fill method to add rows to a DataTable.

Note

When handling batch SQL statements that return multiple results, the implementation of FillSchema 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 Fill with the MissingSchemaAction set to AddWithKey.

When using FillSchema, the .NET Framework Data Provider for SQL Server appends a FOR BROWSE clause to the statement being executed. The user should be aware of potential side effects, such as interference with the use of SET FMTONLY ON statements. For more information, see SET FMTONLY (Transact-SQL).

Notes to Inheritors

This implementation of the FillSchema(DataSet, SchemaType) method is protected and is designed for use by a .NET Framework data provider.

See also

Applies to

FillSchema(DataTable, SchemaType, IDbCommand, CommandBehavior)

Source:
DbDataAdapter.cs
Source:
DbDataAdapter.cs
Source:
DbDataAdapter.cs

Configures the schema of the specified DataTable based on the specified SchemaType, command string, and CommandBehavior values.

protected:
 virtual System::Data::DataTable ^ FillSchema(System::Data::DataTable ^ dataTable, System::Data::SchemaType schemaType, System::Data::IDbCommand ^ command, System::Data::CommandBehavior behavior);
protected virtual System.Data.DataTable? FillSchema (System.Data.DataTable dataTable, System.Data.SchemaType schemaType, System.Data.IDbCommand command, System.Data.CommandBehavior behavior);
protected virtual System.Data.DataTable FillSchema (System.Data.DataTable dataTable, System.Data.SchemaType schemaType, System.Data.IDbCommand command, System.Data.CommandBehavior behavior);
override this.FillSchema : System.Data.DataTable * System.Data.SchemaType * System.Data.IDbCommand * System.Data.CommandBehavior -> System.Data.DataTable
Protected Overridable Function FillSchema (dataTable As DataTable, schemaType As SchemaType, command As IDbCommand, behavior As CommandBehavior) As DataTable

Parameters

dataTable
DataTable

The DataTable to be filled with the schema from the data source.

schemaType
SchemaType

One of the SchemaType values.

command
IDbCommand

The SQL SELECT statement used to retrieve rows from the data source.

behavior
CommandBehavior

One of the CommandBehavior values.

Returns

A of DataTable object that contains schema information returned from the data source.

Remarks

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

A FillSchema operation adds a DataTable to the destination DataSet. It then adds columns to the DataColumnCollection of the DataTable, and configures the following DataColumn properties if they exist at the data source:

FillSchema also configures the PrimaryKey and Constraints properties according to the following rules:

  • If one or more primary key columns are returned by the SelectCommand, they are used as the primary key columns for the DataTable.

  • 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 UniqueConstraint is added to the ConstraintCollection, but the 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 DataTable.

Note that primary keys and unique constraints are added to the 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 Hints (Transact-SQL) - Query.

If the IDataAdapter encounters duplicate columns while populating a 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 DataSet according to the pattern "Column1", "Column2", and so on. When multiple result sets are added to the 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.). If your app uses column and table names, ensure there are no conflicts with these naming patterns.

FillSchema does not return any rows. Use the Fill method to add rows to a DataTable.

Note

When handling batch SQL statements that return multiple results, the implementation of FillSchema 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 Fill with the MissingSchemaAction set to AddWithKey.

When using FillSchema, the .NET Framework Data Provider for SQL Server appends a FOR BROWSE clause to the statement being executed. The user should be aware of potential side effects, such as interference with the use of SET FMTONLY ON statements. For more information, see SET FMTONLY (Transact-SQL).

Notes to Inheritors

This implementation of the FillSchema(DataSet, SchemaType) method is protected and is designed for use by a .NET Framework data provider.

See also

Applies to

FillSchema(DataSet, SchemaType, String)

Source:
DbDataAdapter.cs
Source:
DbDataAdapter.cs
Source:
DbDataAdapter.cs

Adds a DataTable to the specified DataSet and configures the schema to match that in the data source based upon the specified SchemaType and DataTable.

public:
 cli::array <System::Data::DataTable ^> ^ FillSchema(System::Data::DataSet ^ dataSet, System::Data::SchemaType schemaType, System::String ^ srcTable);
public System.Data.DataTable[] FillSchema (System.Data.DataSet dataSet, System.Data.SchemaType schemaType, string srcTable);
override this.FillSchema : System.Data.DataSet * System.Data.SchemaType * string -> System.Data.DataTable[]
Public Function FillSchema (dataSet As DataSet, schemaType As SchemaType, srcTable As String) As DataTable()

Parameters

dataSet
DataSet

A DataSet to insert the schema in.

schemaType
SchemaType

One of the SchemaType values that specify how to insert the schema.

srcTable
String

The name of the source table to use for table mapping.

Returns

A reference to a collection of DataTable objects that were added to the DataSet.

Exceptions

A source table from which to get the schema could not be found.

Examples

The following example uses the derived class, SqlDataAdapter, to fill a DataSet with the schema, and returns a DataSet.

public static DataSet GetCustomerData(string dataSetName,
    string connectionString)
{
    DataSet dataSet = new DataSet(dataSetName);

    using (SqlConnection connection = new SqlConnection(connectionString))
    {
        SqlDataAdapter adapter = new SqlDataAdapter(
            "SELECT CustomerID, CompanyName, ContactName FROM dbo.Customers", connection);

        DataTableMapping mapping = adapter.TableMappings.Add("Table", "Customers");
        mapping.ColumnMappings.Add("CompanyName", "Name");
        mapping.ColumnMappings.Add("ContactName", "Contact");

        connection.Open();

        adapter.FillSchema(dataSet, SchemaType.Source, "Customers");
        adapter.Fill(dataSet);

        return dataSet;
    }
}
Private Function GetCustomerData(ByVal dataSetName As String, _
    ByVal connectionString As String) As DataSet

    Dim dataSet As New DataSet(dataSetName)

    Using connection As SqlConnection = New SqlConnection(connectionString)

        Dim adapter As New SqlDataAdapter( _
           "SELECT CustomerID, CompanyName, ContactName FROM dbo.Customers", _
           connection)

        Dim mapping As DataTableMapping = adapter.TableMappings.Add( _
           "Table", "Customers")
        mapping.ColumnMappings.Add("CompanyName", "Name")
        mapping.ColumnMappings.Add("ContactName", "Contact")

        connection.Open()

        adapter.FillSchema(dataSet, SchemaType.Source, "Customers")
        adapter.Fill(dataSet)
        Return dataSet
    End Using
End Function

Remarks

This method retrieves the schema information from the data source using the SelectCommand.

A FillSchema operation adds a DataTable to the destination DataSet. It then adds columns to the DataColumnCollection of the DataTable, and configures the following DataColumn properties if they exist at the data source:

FillSchema also configures the PrimaryKey and Constraints properties according to the following rules:

  • If one or more primary key columns are returned by the SelectCommand, they are used as the primary key columns for the DataTable.

  • 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 UniqueConstraint is added to the ConstraintCollection, but the 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 DataTable.

Note that primary keys and unique constraints are added to the 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 Hints (Transact-SQL) - Query.

Primary key information is used during Fill to find and replace any rows whose key columns match. If this is not the desired behavior, use Fill without requesting schema information.

If the DbDataAdapter encounters duplicate columns while populating a 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 DataSet according to the pattern "Column1", "Column2", and so on. When multiple result sets are added to the 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.). If your app uses column and table names, ensure there are no conflicts with these naming patterns.

The FillSchema method supports scenarios where the DataSet contains multiple DataTable objects whose names differ only by case. In such situations, FillSchema performs a case-sensitive comparison to find the corresponding table, and creates a new table if no exact match exists. The following C# code illustrates this behavior.

DataSet dataset = new DataSet();  
dataset.Tables.Add("aaa");  
dataset.Tables.Add("AAA");  
adapter.FillSchema(dataset, "aaa"); // Fills the schema of "aaa", which already exists in the DataSet.  
adapter.FillSchema(dataset, "Aaa"); // Adds a new table called "Aaa".  

If FillSchema is called and the DataSet contains only one DataTable whose name differs only by case, that DataTable is updated. In this scenario, the comparison is case insensitive. The following C# code illustrates this behavior.

DataSet dataset = new DataSet();  
dataset.Tables.Add("aaa");  
adapter.FillSchema(dataset, "AAA"); // Fills the schema of table "aaa" because only one similarly named table is in the DataSet.  

The IDbConnection object associated with the select command must be valid, but it does not need to open. If the IDbConnection is closed before FillSchema is called, it is opened to retrieve data, then closed. If the connection is open before FillSchema is called, it is left open.

Note

When handling batch SQL statements that return multiple results, the implementation of FillSchema 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 Fill with the MissingSchemaAction set to AddWithKey.

When using FillSchema, the .NET Framework Data Provider for SQL Server appends a FOR BROWSE clause to the statement being executed. The user should be aware of potential side effects, such as interference with the use of SET FMTONLY ON statements. For more information, see SET FMTONLY (Transact-SQL).

See also

Applies to

FillSchema(DataTable, SchemaType)

Source:
DbDataAdapter.cs
Source:
DbDataAdapter.cs
Source:
DbDataAdapter.cs

Configures the schema of the specified DataTable based on the specified SchemaType.

public:
 System::Data::DataTable ^ FillSchema(System::Data::DataTable ^ dataTable, System::Data::SchemaType schemaType);
public System.Data.DataTable? FillSchema (System.Data.DataTable dataTable, System.Data.SchemaType schemaType);
public System.Data.DataTable FillSchema (System.Data.DataTable dataTable, System.Data.SchemaType schemaType);
override this.FillSchema : System.Data.DataTable * System.Data.SchemaType -> System.Data.DataTable
Public Function FillSchema (dataTable As DataTable, schemaType As SchemaType) As DataTable

Parameters

dataTable
DataTable

The DataTable to be filled with the schema from the data source.

schemaType
SchemaType

One of the SchemaType values.

Returns

A DataTable that contains schema information returned from the data source.

Examples

The following example uses the derived class, SqlDataAdapter, to fill a DataSet with the schema, and returns a DataTable.

public static DataTable GetCustomerData(string dataSetName,
    string connectionString)
{
    DataTable table = new DataTable(dataSetName);

    using (SqlConnection connection = new SqlConnection(connectionString))
    {
        SqlDataAdapter adapter = new SqlDataAdapter(
            "SELECT CustomerID, CompanyName, ContactName FROM dbo.Customers", connection);

        DataTableMapping mapping = adapter.TableMappings.Add("Table", "Customers");
        mapping.ColumnMappings.Add("CompanyName", "Name");
        mapping.ColumnMappings.Add("ContactName", "Contact");

        connection.Open();

        adapter.FillSchema(table, SchemaType.Mapped);
        adapter.Fill(table);
        return table;
    }
}
Private Function GetCustomerData(ByVal dataTableName As String, _
    ByVal connectionString As String) As DataTable

    Dim table As New DataTable(dataTableName)

    Using connection As SqlConnection = New SqlConnection(connectionString)

        Dim adapter New SqlDataAdapter( _
           "SELECT CustomerID, CompanyName, ContactName FROM dbo.Customers", _
           connection)

        Dim mapping As DataTableMapping = adapter.TableMappings.Add( _
           "Table", "Customers")
        mapping.ColumnMappings.Add("CompanyName", "Name")
        mapping.ColumnMappings.Add("ContactName", "Contact")

        connection.Open()

        adapter.FillSchema(table, SchemaType.Mapped)
        adapter.Fill(table)
        Return table
    End Using
End Function

Remarks

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

A FillSchema operation returns a DataTable. It then adds columns to the DataColumnCollection of the DataTable, and configures the following DataColumn properties if they exist at the data source:

FillSchema also configures the PrimaryKey and Constraints properties according to the following rules:

  • If a PrimaryKey has already been defined for the DataTable, or the DataTable contains data, the PrimaryKey property will not be set.

  • If one or more primary key columns are returned by the SelectCommand, they are used as the primary key columns for the DataTable.

  • 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 UniqueConstraint is added to the ConstraintCollection, but the 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 DataTable.

Note that primary keys and unique constraints are added to the ConstraintCollection according to the preceding rules, but other constraint types are not added. This process may require several round-trips to the server.

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 Hints (Transact-SQL) - Query.

If the DbDataAdapter encounters duplicate columns while populating a 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 DataSet according to the pattern "Column1", "Column2", and so on. When multiple result sets are added to the 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.). If your app uses column and table names, ensure there are no conflicts with these naming patterns.

FillSchema does not return any rows. Use the Fill method to add rows to a DataTable.

Note

When handling batch SQL statements that return multiple results, the implementation of FillSchema 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 Fill with the MissingSchemaAction set to AddWithKey.

When using FillSchema, the .NET Framework Data Provider for SQL Server appends a FOR BROWSE clause to the statement being executed. The user should be aware of potential side effects, such as interference with the use of SET FMTONLY ON statements. For more information, see SET FMTONLY (Transact-SQL).

See also

Applies to

FillSchema(DataSet, SchemaType)

Source:
DbDataAdapter.cs
Source:
DbDataAdapter.cs
Source:
DbDataAdapter.cs

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

public:
 override cli::array <System::Data::DataTable ^> ^ FillSchema(System::Data::DataSet ^ dataSet, System::Data::SchemaType schemaType);
public override System.Data.DataTable[] FillSchema (System.Data.DataSet dataSet, System.Data.SchemaType schemaType);
override this.FillSchema : System.Data.DataSet * System.Data.SchemaType -> System.Data.DataTable[]
Public Overrides Function FillSchema (dataSet As DataSet, schemaType As SchemaType) As DataTable()

Parameters

dataSet
DataSet

A DataSet to insert the schema in.

schemaType
SchemaType

One of the SchemaType values that specify how to insert the schema.

Returns

A reference to a collection of DataTable objects that were added to the DataSet.

Implements

Examples

The following example uses the derived class, SqlDataAdapter, to fill a DataSet with the schema, and returns a DataSet.

public static DataSet GetCustomerData(string dataSetName,
    string connectionString)
{
    DataSet dataSet = new DataSet(dataSetName);

    using (SqlConnection connection = new SqlConnection(connectionString))
    {
        SqlDataAdapter adapter = new SqlDataAdapter(
            "SELECT CustomerID, CompanyName, ContactName FROM dbo.Customers", connection);

        DataTableMapping mapping = adapter.TableMappings.Add("Table", "Customers");
        mapping.ColumnMappings.Add("CompanyName", "Name");
        mapping.ColumnMappings.Add("ContactName", "Contact");

        connection.Open();

        adapter.FillSchema(dataSet, SchemaType.Mapped);
        adapter.Fill(dataSet);

        return dataSet;
    }
}
Private Function GetCustomerData(ByVal dataSetName As String, _
    ByVal connectionString As String) As DataSet

    Dim dataSet As New DataSet(dataSetName)

    Using connection As SqlConnection = New SqlConnection(connectionString)
        Dim adapter As New SqlDataAdapter( _
           "SELECT CustomerID, CompanyName, ContactName FROM dbo.Customers", _
           connection)

        Dim mapping As DataTableMapping = adapter.TableMappings.Add( _
           "Table", "Customers")
        mapping.ColumnMappings.Add("CompanyName", "Name")
        mapping.ColumnMappings.Add("ContactName", "Contact")

        connection.Open()

        adapter.FillSchema(dataSet, SchemaType.Mapped)
        adapter.Fill(dataSet)
        Return dataSet
    End Using
End Function

Remarks

This method retrieves the schema information from the data source using the SelectCommand.

A FillSchema operation adds a DataTable to the destination DataSet. It then adds columns to the DataColumnCollection of the DataTable, and configures the following DataColumn properties if they exist at the data source:

FillSchema also configures the PrimaryKey and Constraints properties according to the following rules:

  • If one or more primary key columns are returned by the SelectCommand, they are used as the primary key columns for the DataTable.

  • 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 UniqueConstraint is added to the ConstraintCollection, but the 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 DataTable.

Note that primary keys and unique constraints are added to the 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 Hints (Transact-SQL) - Query.

Primary key information is used during Fill to find and replace any rows whose key columns match. If this is not the desired behavior, use Fill without requesting schema information.

If the IDataAdapter encounters duplicate columns while populating a 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 DataSet according to the pattern "Column1", "Column2", and so on. When multiple result sets are added to the 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.). If your app uses column and table names, ensure there are no conflicts with these naming patterns.

The IDbConnection object associated with the select command must be valid, but it does not need to open. If the IDbConnection is closed before FillSchema is called, it is opened to retrieve data, then closed. If the connection is open before FillSchema is called, it is left open.

Note

When handling batch SQL statements that return multiple results, the implementation of FillSchema 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 Fill with the MissingSchemaAction set to AddWithKey.

When using FillSchema, the .NET Framework Data Provider for SQL Server appends a FOR BROWSE clause to the statement being executed. The user should be aware of potential side effects, such as interference with the use of SET FMTONLY ON statements. For more information, see SET FMTONLY (Transact-SQL).

See also

Applies to