System.Data Namespace IDataAdapter Class
Loads a DataTable to the specified DataSet and configures the schema to match that in the data source based on the specified SchemaType.
[ VB ]
Function FillSchema ( _
ByVal dataSet As DataSet, _
ByVal schemaType As SchemaType _
) As DataTable ( )
[ C# ] DataTable [ ] FillSchema (
DataSet dataSet,
SchemaType schemaType
);
[ C++ ] DataTable* FillSchema (
DataSet* dataSet,
SchemaType schemaType
) [ ] = 0;
[ JScript ]
function FillSchema (
dataSet : DataSet,
schemaType : SchemaType
) : DataTable [ ];
- dataSet
- The DataSet to be filled with the schema from the data source.
- schemaType
- One of the SchemaType values.
An array of DataTable objects that contain schema information returned from the data source.
The FillSchema method adds a DataTable to a given DataSet object, and configures the table structure or schema to match that in the data source based on the given SchemaType.
The FillSchema method retrieves the schema from the data source using the SELECT statement specified by the SelectCommand associated with the IDataAdapter. The IDbConnection associated with the SelectCommand must be valid, but it does not need to be open. If the IDbConnection 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 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 of 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.
NOTE: When using FillSchema, the SQL Server™ .NET Data Provider 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. See SQL Server Books Online for more information.
FillSchema does not return any rows. To add rows to the DataTable, use the Fill method.
NOTE: When handling batch SQL statements that return multiple results, the implementation of FillSchema for the OLE DB .NET Data Provider 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, 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.
The following example shows using FillSchema to retrieve the schema information of a DataSet.
public void GetMyRecords ( ) {
// . . . code to initialize DataAdapter and DataSet here . . .
DataTable [ ] myTableArray = myDataAdapter.FillSchema (
myData, SchemaType.Mapped );
}
Public Sub GetMyRecords ( )
' . . . code to initialize DataAdapter and DataSet here . . .
Dim myTableArray As DataTable ( ) = myDataAdapter.FillSchema ( _
myData, SchemaType.Mapped )
End Sub |
|
C# |
VB |
IDataAdapter Members Fill