System.Data.Common.DbDataAdapter.Fill Method

Adds or refreshes rows in the System.Data.DataSet.

Syntax

public override int Fill (System.Data.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

The DbDataAdapter.Fill(System.Data.DataSet) method retrieves the data from the data source using a SELECT statement. The System.Data.IDbConnection object associated with the select command must be valid, but it does not need to be open. If the System.Data.IDbConnection is closed before DbDataAdapter.Fill(System.Data.DataSet) is called, it is opened to retrieve data and then closed. If the connection is open before DbDataAdapter.Fill(System.Data.DataSet) is called, it remains open.

If an error or an exception is encountered while populating the data tables, rows added prior to the occurrence of the error remain in the data tables. The remainder of the operation is aborted.

If a command does not return any rows, no tables are added to the System.Data.DataSet, and no exception is raised.

If the System.Data.Common.DbDataAdapter object encounters duplicate columns while populating a System.Data.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 System.Data.DataSet according to the pattern "Column1", "Column2", and so on.

When the query specified returns multiple results, the result set for each row returning query 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). Because no table is created for a query that does not return rows, if you process an insert query followed by a select query, the table created for the select query is named "Table" because it is the first table created. Applications using column and table names should ensure that conflicts with these naming patterns does not occur.

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

When using subsequent DbDataAdapter.Fill(System.Data.DataSet) calls to refresh the contents of the System.Data.DataSet, two conditions must be met:

[The 'ordered' type of list has not been implemented in the ECMA stylesheet.]

If primary key information is present, any duplicate rows are reconciled and only appear once in the System.Data.DataTable that corresponds to the System.Data.DataSet. Primary key information may be set either through DbDataAdapter.FillSchema(System.Data.DataTable, System.Data.SchemaType), by specifying the System.Data.DataTable.PrimaryKey property of the System.Data.DataTable, or by setting the DataAdapter.MissingSchemaAction property to AddWithKey.

If the SelectCommand returns the results of an OUTER JOIN, the DataAdapter does not set a System.Data.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 Defining a Primary Key for a Table.

Note:

When handling batch SQL statements that return multiple results, the implementation of DbDataAdapter.FillSchema(System.Data.DataTable, System.Data.SchemaType) 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 DbDataAdapter.Fill(System.Data.DataSet) with the System.Data.MissingSchemaAction set to AddWithKey.

Requirements

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