DataAdapter.Fill 方法

定义

DataSet 中添加或刷新行以与数据源中的行匹配。Adds or refreshes rows in the DataSet to match those in the data source.

重载

Fill(DataSet)

DataSet 中添加或刷新行以与数据源中的行匹配。Adds or refreshes rows in the DataSet to match those in the data source.

Fill(DataTable, IDataReader)

DataTable 中添加或刷新行以与使用 DataTable 名称和指定的 IDataReader 的数据源中的行匹配。Adds or refreshes rows in the DataTable to match those in the data source using the DataTable name and the specified IDataReader.

Fill(DataTable[], IDataReader, Int32, Int32)

DataTable 对象集合的指定范围中添加或刷新行以与数据源中的行匹配。Adds or refreshes rows in a specified range in the collection of DataTable objects to match those in the data source.

Fill(DataSet, String, IDataReader, Int32, Int32)

DataSet 的指定范围中添加或刷新行以匹配使用 DataSetDataTable 名称的数据源中的行。Adds or refreshes rows in a specified range in the DataSet to match those in the data source using the DataSet and DataTable names.

Fill(DataSet)

DataSet 中添加或刷新行以与数据源中的行匹配。Adds or refreshes rows in the DataSet to match those in the data source.

public:
 virtual int Fill(System::Data::DataSet ^ dataSet);
public:
 abstract int Fill(System::Data::DataSet ^ dataSet);
public virtual int Fill (System.Data.DataSet dataSet);
public abstract int Fill (System.Data.DataSet dataSet);
abstract member Fill : System.Data.DataSet -> int
override this.Fill : System.Data.DataSet -> int
abstract member Fill : System.Data.DataSet -> int
Public Overridable Function Fill (dataSet As DataSet) As Integer
Public MustOverride Function Fill (dataSet As DataSet) As Integer

参数

dataSet
DataSet

要用记录和架构(如果必要)填充的 DataSetA DataSet to fill with records and, if necessary, schema.

返回

Int32

已在 DataSet 中成功添加或刷新的行数。The number of rows successfully added to or refreshed in the DataSet. 这不包括受不返回行的语句影响的行。This does not include rows affected by statements that do not return rows.

实现

注解

Fill 方法使用关联的 SelectCommand 属性指定的 SELECT 语句从数据源中检索行。The Fill method retrieves rows from the data source using the SELECT statement specified by an associated SelectCommand property. 与 SELECT 语句关联的连接对象必须有效,但不需要打开。The connection object associated with the SELECT statement must be valid, but it does not need to be open. 如果在调用 Fill 之前关闭连接,则会打开该连接,以检索数据,然后关闭。If the connection is closed before Fill is called, it is opened to retrieve data, then closed. 如果在调用 Fill 之前连接处于打开状态,则该连接将保持打开状态。If the connection is open before Fill is called, it remains open.

然后 Fill 操作将行添加到 DataSet中的目标 DataTable 对象,并创建 DataTable 对象(如果它们尚不存在)。The Fill operation then adds the rows to destination DataTable objects in the DataSet, creating the DataTable objects if they do not already exist. 创建 DataTable 对象时,Fill 操作通常只创建列名称元数据。When creating DataTable objects, the Fill operation normally creates only column name metadata. 但是,如果 MissingSchemaAction 属性设置为 AddWithKey,则还会创建相应的主键和约束。However, if the MissingSchemaAction property is set to AddWithKey, appropriate primary keys and constraints are also created.

如果 SelectCommand 返回 OUTER JOIN 的结果,则 DataAdapter 不会为生成的 PrimaryKey 设置 DataTable值。If the SelectCommand returns the results of an OUTER JOIN, the DataAdapter does not set a PrimaryKey value for the resulting DataTable. 必须显式定义主键,以确保正确解析重复行。You must explicitly define the primary key to ensure that duplicate rows are resolved correctly. 有关详细信息,请参阅定义主键For more information, see Defining Primary Keys.

如果数据适配器在填充 DataTable时遇到重复的列,则使用 "columnname1"、"columnname2"、"columnname3" 等模式为后续列生成名称。If the data adapter 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.

当用于填充 DataSet 的 SELECT 语句返回多个结果(如批处理 SQL 语句)时,如果其中一个结果包含错误,则会跳过所有后续结果,并且不会将其添加到 DataSet中。When the SELECT statement used to populate the DataSet returns multiple results, such as a batch SQL statements, if one of the results contains an error, all subsequent results are skipped and not added to the DataSet.

您可以在同一 DataTable上多次使用 Fill 方法。You can use the Fill method multiple times on the same DataTable. 如果存在主键,则传入行与已存在的匹配行合并在一起。If a primary key exists, incoming rows are merged with matching rows that already exist. 如果主键不存在,将在 DataTable中追加传入行。If no primary key exists, incoming rows are appended to the 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.

另请参阅

Fill(DataTable, IDataReader)

DataTable 中添加或刷新行以与使用 DataTable 名称和指定的 IDataReader 的数据源中的行匹配。Adds or refreshes rows in the DataTable to match those in the data source using the DataTable name and the specified IDataReader.

protected:
 virtual int Fill(System::Data::DataTable ^ dataTable, System::Data::IDataReader ^ dataReader);
protected virtual int Fill (System.Data.DataTable dataTable, System.Data.IDataReader dataReader);
abstract member Fill : System.Data.DataTable * System.Data.IDataReader -> int
override this.Fill : System.Data.DataTable * System.Data.IDataReader -> int
Protected Overridable Function Fill (dataTable As DataTable, dataReader As IDataReader) As Integer

参数

dataTable
DataTable

一个要用记录填充的 DataTableA DataTable to fill with records.

dataReader
IDataReader

IDataReader 的实例。An instance of IDataReader.

返回

Int32

已在 DataTable 中成功添加或刷新的行数。The number of rows successfully added to or refreshed in the DataTable. 这不包括受不返回行的语句影响的行。This does not include rows affected by statements that do not return rows.

注解

有关其他信息,请参阅 DataAdapter.Fill(DataSet) 的备注。See the remarks for DataAdapter.Fill(DataSet) for additional information.

另请参阅

Fill(DataTable[], IDataReader, Int32, Int32)

DataTable 对象集合的指定范围中添加或刷新行以与数据源中的行匹配。Adds or refreshes rows in a specified range in the collection of DataTable objects to match those in the data source.

protected:
 virtual int Fill(cli::array <System::Data::DataTable ^> ^ dataTables, System::Data::IDataReader ^ dataReader, int startRecord, int maxRecords);
protected virtual int Fill (System.Data.DataTable[] dataTables, System.Data.IDataReader dataReader, int startRecord, int maxRecords);
abstract member Fill : System.Data.DataTable[] * System.Data.IDataReader * int * int -> int
override this.Fill : System.Data.DataTable[] * System.Data.IDataReader * int * int -> int
Protected Overridable Function Fill (dataTables As DataTable(), dataReader As IDataReader, startRecord As Integer, maxRecords As Integer) As Integer

参数

dataTables
DataTable[]

要用记录填充的 DataTable 对象的集合。A collection of DataTable objects to fill with records.

dataReader
IDataReader

IDataReader 的实例。An instance of IDataReader.

startRecord
Int32

起始记录的从零开始的索引。The zero-based index of the starting record.

maxRecords
Int32

指示最大记录数的整数。An integer indicating the maximum number of records.

返回

Int32

已在 DataTable 中成功添加或刷新的行数。The number of rows successfully added to or refreshed in the DataTable. 这不包括受不返回行的语句影响的行。This does not include rows affected by statements that do not return rows.

注解

有关其他信息,请参阅 System.Data.Common.DataAdapter.Fill(System.Data.DataSet) 的备注。See the remarks for System.Data.Common.DataAdapter.Fill(System.Data.DataSet) for additional information.

另请参阅

Fill(DataSet, String, IDataReader, Int32, Int32)

DataSet 的指定范围中添加或刷新行以匹配使用 DataSetDataTable 名称的数据源中的行。Adds or refreshes rows in a specified range in the DataSet to match those in the data source using the DataSet and DataTable names.

protected:
 virtual int Fill(System::Data::DataSet ^ dataSet, System::String ^ srcTable, System::Data::IDataReader ^ dataReader, int startRecord, int maxRecords);
protected virtual int Fill (System.Data.DataSet dataSet, string srcTable, System.Data.IDataReader dataReader, int startRecord, int maxRecords);
abstract member Fill : System.Data.DataSet * string * System.Data.IDataReader * int * int -> int
override this.Fill : System.Data.DataSet * string * System.Data.IDataReader * int * int -> int
Protected Overridable Function Fill (dataSet As DataSet, srcTable As String, dataReader As IDataReader, startRecord As Integer, maxRecords As Integer) As Integer

参数

dataSet
DataSet

一个要用记录填充的 DataSetA DataSet to fill with records.

srcTable
String

一个字符串,指示源表的名称。A string indicating the name of the source table.

dataReader
IDataReader

IDataReader 的实例。An instance of IDataReader.

startRecord
Int32

起始记录的从零开始的索引。The zero-based index of the starting record.

maxRecords
Int32

指示最大记录数的整数。An integer indicating the maximum number of records.

返回

Int32

已在 DataSet 中成功添加或刷新的行数。The number of rows successfully added to or refreshed in the DataSet. 这不包括受不返回行的语句影响的行。This does not include rows affected by statements that do not return rows.

注解

有关其他信息,请参阅 System.Data.Common.DataAdapter.Fill(System.Data.DataSet) 的备注。See the remarks for System.Data.Common.DataAdapter.Fill(System.Data.DataSet) for additional information.

另请参阅

适用于