Επεξεργασία

Κοινή χρήση μέσω


DataAdapter.FillSchema Method

Definition

Adds a DataTable to the specified DataSet.

Overloads

FillSchema(DataSet, SchemaType, String, IDataReader)

Adds a DataTable to the specified DataSet.

FillSchema(DataSet, SchemaType)

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, IDataReader)

Adds a DataTable to the specified DataSet.

FillSchema(DataSet, SchemaType, String, IDataReader)

Source:
DataAdapter.cs
Source:
DataAdapter.cs
Source:
DataAdapter.cs

Adds a DataTable to the specified DataSet.

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

Parameters

dataSet
DataSet

The DataTable to be filled from the IDataReader.

schemaType
SchemaType

One of the SchemaType values.

srcTable
String

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

dataReader
IDataReader

The IDataReader to be used as the data source when filling the DataTable.

Returns

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

See also

Applies to

FillSchema(DataSet, SchemaType)

Source:
DataAdapter.cs
Source:
DataAdapter.cs
Source:
DataAdapter.cs

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

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

Parameters

dataSet
DataSet

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

schemaType
SchemaType

One of the SchemaType values.

Returns

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

Implements

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 and 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

The underlying data store may allow column attributes that are not supported in a DataColumn, which causes some column attributes to not translate correctly. For example, SQL Server allows an identity column with a data type of tinyint whereas a DataColumn only allows Int16, Int32, and Int64 to have the AutoIncrement property set. FillSchema silently ignores cases where the DataColumn cannot accurately mirror the data source and throws no exception.

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 DataAdapter 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). Applications using column and table names should ensure that conflicts with these naming patterns does not occur.

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.

See also

Applies to

FillSchema(DataTable, SchemaType, IDataReader)

Source:
DataAdapter.cs
Source:
DataAdapter.cs
Source:
DataAdapter.cs

Adds a DataTable to the specified DataSet.

protected:
 virtual System::Data::DataTable ^ FillSchema(System::Data::DataTable ^ dataTable, System::Data::SchemaType schemaType, System::Data::IDataReader ^ dataReader);
protected virtual System.Data.DataTable? FillSchema (System.Data.DataTable dataTable, System.Data.SchemaType schemaType, System.Data.IDataReader dataReader);
protected virtual System.Data.DataTable FillSchema (System.Data.DataTable dataTable, System.Data.SchemaType schemaType, System.Data.IDataReader dataReader);
abstract member FillSchema : System.Data.DataTable * System.Data.SchemaType * System.Data.IDataReader -> System.Data.DataTable
override this.FillSchema : System.Data.DataTable * System.Data.SchemaType * System.Data.IDataReader -> System.Data.DataTable
Protected Overridable Function FillSchema (dataTable As DataTable, schemaType As SchemaType, dataReader As IDataReader) As DataTable

Parameters

dataTable
DataTable

The DataTable to be filled from the IDataReader.

schemaType
SchemaType

One of the SchemaType values.

dataReader
IDataReader

The IDataReader to be used as the data source when filling the DataTable.

Returns

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

See also

Applies to