System.Data.IDataAdapter.Fill Method

Adds or updates rows in the System.Data.DataSet to match those in the data source using the System.Data.DataSet name, and creates a System.Data.DataTable named "Table".

Syntax

public int Fill (DataSet dataSet)

Parameters

dataSet
A System.Data.DataSet to fill with records and, if necessary, schema.

Returns

The number of rows successfully added to or refreshed in the System.Data.DataSet. This does not include rows affected by statements that do not return rows.

Remarks

IDataAdapter.Fill(DataSet) retrieves rows from the data source using the SELECT statement specified by an associated IDbDataAdapter.SelectCommand property. The connection object associated with the SELECT statement must be valid, but it does not need to be open. If the connection is closed before IDataAdapter.Fill(DataSet) is called, it is opened to retrieve data, then closed. If the connection is open before IDataAdapter.Fill(DataSet) is called, it remains open.

The IDataAdapter.Fill(DataSet) operation then adds the rows to destination System.Data.DataTable objects in the System.Data.DataSet, creating the System.Data.DataTable objects if they do not already exist. When creating System.Data.DataTable objects, the IDataAdapter.Fill(DataSet) operation usually creates only column name metadata. However, if the IDataAdapter.MissingSchemaAction property is set to AddWithKey, appropriate primary keys and constraints are also created.

If the SelectCommand returns the results of an OUTER JOIN, the DataAdapter does not set a DataTable.PrimaryKey value for the resulting System.Data.DataTable. You must explicitly define the primary key to ensure that duplicate rows are resolved correctly. For more information, see [<topic://cpcondefiningprimarykeyfortable>].

If the System.Data.IDataAdapter encounters duplicate columns while populating a System.Data.DataTable, it generates names for the successive columns, using the pattern "columnname1", "columnname2", "columnname3", and so on. If the incoming data contains unnamed columns, they are put in the System.Data.DataSet according to the pattern "Column1", "Column2", and so on. When multiple result sets are added to the System.Data.DataSet, each result set is put 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 should use caution when using column and table names to ensure that conflicts with these naming patterns do not occur.

When the SELECT statement that is used to populate the System.Data.DataSet returns multiple results, such as a batch SQL statement, if one of the results contains an error, all successive results are skipped and not added to the System.Data.DataSet.

You can use the IDataAdapter.Fill(DataSet) method multiple times on the same System.Data.DataTable. If a primary key exists, incoming rows are merged with matching rows that already exist. If no primary key exists, incoming rows are appended to the System.Data.DataTable.

Note:

When handling batch SQL statements that return multiple results, the implementation of IDataAdapter.Fill(DataSet) and IDataAdapter.FillSchema(DataSet, SchemaType) for a .NET Framework data provider retrieves schema information for only the first result.

Requirements

Namespace: System.Data
Assembly: System.Data (in System.Data.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0