DataAdapter.FillSchema 方法

定义

向指定的 DataTable 添加一个 DataSetAdds a DataTable to the specified DataSet.

重载

FillSchema(DataSet, SchemaType, String, IDataReader)

向指定的 DataTable 添加一个 DataSetAdds a DataTable to the specified DataSet.

FillSchema(DataSet, SchemaType)

DataTable 添加到指定的 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)

向指定的 DataTable 添加一个 DataSetAdds a DataTable to the specified DataSet.

FillSchema(DataSet, SchemaType, String, IDataReader)

向指定的 DataTable 添加一个 DataSetAdds 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[]

参数

dataSet
DataSet

要从 DataTable 填充的 IDataReaderThe DataTable to be filled from the IDataReader.

schemaType
SchemaType

SchemaType 值之一。One of the SchemaType values.

srcTable
String

用于表映射的源表的名称。The name of the source table to use for table mapping.

dataReader
IDataReader

填充 IDataReader 时要用作数据源的 DataTableThe IDataReader to be used as the data source when filling the DataTable.

返回

一个引用,指向添加到 DataSetDataTable 对象的集合。A reference to a collection of DataTable objects that were added to the DataSet.

另请参阅

FillSchema(DataSet, SchemaType)

DataTable 添加到指定的 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.

public:
 abstract cli::array <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[]

参数

dataSet
DataSet

要用数据源中的架构填充的 DataSetThe DataSet to be filled with the schema from the data source.

schemaType
SchemaType

SchemaType 值之一。One of the SchemaType values.

返回

包含从数据源返回的架构信息的 DataTable 对象。A DataTable object that contains schema information returned from the data source.

实现

注解

FillSchema 方法使用 SelectCommand从数据源检索架构。The FillSchema method retrieves the schema from the data source using the SelectCommand. SelectCommand 关联的连接对象必须有效,但不需要打开。The connection object associated with the SelectCommand must be valid, but it does not need to be open. 如果在调用 FillSchema 之前关闭连接,则会打开该连接,以检索数据,然后将其关闭。If the connection is closed before FillSchema is called, it is opened to retrieve data and then closed. 如果在调用 FillSchema 之前连接处于打开状态,则该连接将保持打开状态。If the connection is open before FillSchema is called, it remains open.

FillSchema 操作向目标 DataSet添加 DataTableA FillSchema operation adds a DataTable to the destination DataSet. 然后,将列添加到 DataTableDataColumnCollection 中,并配置以下 DataColumn 属性(如果它们存在于数据源中):It then adds columns to the DataColumnCollection of the DataTable, and configures the following DataColumn properties if they exist at the data source:

FillSchema 还根据以下规则配置 PrimaryKeyConstraints 属性:FillSchema also configures the PrimaryKey and Constraints properties according to the following rules:

  • 如果 SelectCommand返回一个或多个主键列,则将它们用作 DataTable的主键列。If one or more primary key columns are returned by the SelectCommand, they are used as the primary key columns for the DataTable.

  • 如果未返回主键列但唯一列为,则当且仅当不可 null 所有唯一列时,才将唯一列用作主键。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. 如果任何列可为 null,则会将 UniqueConstraint 添加到 ConstraintCollection,但不会设置 PrimaryKey 属性。If any of the columns are nullable, a UniqueConstraint is added to the ConstraintCollection, but the PrimaryKey property is not set.

  • 如果为主键列和唯一列都返回,则主键列将用作 DataTable的主键列。If both primary key columns and unique columns are returned, the primary key columns are used as the primary key columns for the DataTable.

备注

基础数据存储可能会允许 DataColumn不支持的列属性,这将导致某些列属性无法正确转换。The underlying data store may allow column attributes that are not supported in a DataColumn, which causes some column attributes to not translate correctly. 例如,SQL Server 允许数据类型为 tinyint 的标识列,而 DataColumn 只允许 Int16、Int32 和 Int64 设置 AutoIncrement 属性。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 以无提示方式忽略 DataColumn 无法准确镜像数据源并且不引发异常的情况。FillSchema silently ignores cases where the DataColumn cannot accurately mirror the data source and throws no exception.

请注意,根据前面的规则将主键和 unique 约束添加到 ConstraintCollection 中,但不会添加其他约束类型。Note that primary keys and unique constraints are added to the ConstraintCollection according to the preceding rules, but other constraint types are not added.

如果在 SQL Server 表中的一列或多列上定义了唯一聚集索引,并且在一组单独的列上定义了 primary key 约束,则将返回聚集索引中的列的名称。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. 若要返回主键列的名称,请使用带有指定主键索引名称的 SELECT 语句的查询提示。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. 有关指定查询提示的详细信息,请参阅查询提示(transact-sql)For more information about specifying query hints, see Query Hint (Transact-SQL).

如果 DataAdapter 在填充 DataTable时遇到重复的列,则它将使用模式 "columnname1"、"columnname2"、"columnname3" 等来为后续列生成名称。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. 如果传入数据包含未命名列,则这些列将按照模式 "Column1"、"Column2" 等放置在 DataSet 中。If the incoming data contains unnamed columns, they are placed in the DataSet according to the pattern "Column1", "Column2", and so on. 当将多个结果集添加到 DataSet 时,每个结果集将放在一个单独的表中。When multiple result sets are added to the DataSet each result set is placed in a separate table. 附加的结果集通过将整数值追加到指定的表名来命名(例如,"表"、"Table1"、"Table2" 等)。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 不返回任何行。FillSchema does not return any rows. 使用 Fill 方法将行添加到 DataTable中。Use the Fill method to add rows to a DataTable.

备注

当处理返回多个结果的批处理 SQL 语句时,OLE DB 的 .NET Framework 数据提供程序 FillSchema 的实现仅检索第一个结果的架构信息。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. 若要检索多个结果的架构信息,请使用 Fill,并将 MissingSchemaAction 设置为 AddWithKeyTo retrieve schema information for multiple results, use Fill with the MissingSchemaAction set to AddWithKey.

另请参阅

FillSchema(DataTable, SchemaType, IDataReader)

向指定的 DataTable 添加一个 DataSetAdds 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);
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

参数

dataTable
DataTable

要从 DataTable 填充的 IDataReaderThe DataTable to be filled from the IDataReader.

schemaType
SchemaType

SchemaType 值之一。One of the SchemaType values.

dataReader
IDataReader

填充 IDataReader 时要用作数据源的 DataTableThe IDataReader to be used as the data source when filling the DataTable.

返回

包含从数据源返回的架构信息的 DataTable 对象。A DataTable object that contains schema information returned from the data source.

另请参阅

适用于