asp.net.ph

DbDataAdapter.Fill Method ( DataTable )

System.Data.Common Namespace   DbDataAdapter Class


Adds or refreshes rows in a DataTable to match those in the data source using the DataTable name.

[ VB ]
Overloads Public Function Fill ( _
   ByVal dataTable As DataTable _
) As Integer

[ C# ]
public int Fill (
   DataTable dataTable
);

[ C++ ]
public: int Fill (
   DataTable* dataTable
 ) = 0;

[ JScript ]
public function Fill (
   dataTable : DataTable
) : int;

Parameters

dataTable
A DataTable to fill with records and, if necessary, schema.

Return Value

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.

Remarks

The Fill method retrieves rows from the data source using the SELECT statement specified by an associated 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 Fill is called, it is opened to retrieve data, then closed. If the connection is open before Fill is called, it remains open.

The Fill operation then adds the rows to the specified destination DataTable object in the DataSet, creating the DataTable objects if they do not already exist. When creating DataTable objects, the Fill operation normally initializes only column name metadata. However, if the MissingSchemaAction property is set to AddWithKey, appropriate primary keys and constraints are also created.

If the DbDataAdapter object encounters duplicate columns while populating a 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 DataTable 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. ). Since no table is created for a query that does not return rows, if you were to process an insert query followed by a select query, the table created for the select query would be named "Table" since it is the first table created. Applications should use caution when using column and table names to ensure that no naming conflict occurs.

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.

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. If no primary key exists, incoming rows are appended to the DataTable.

Example

The following example shows how to use Fill to populate a DataSet using this constructor.

void FillDemo ( ) {
   // . . . code to initialize DataAdapter and DataSet here . . .

   myDataAdapter.Fill ( myDataTable );
}
  C# VB

See Also

DbDataAdapter Members   DbDataAdapter.Fill Overload List Skip Navigation Links




Home
Suggested Reading


Previous page Back to top Next page

© 2000-2010 Rey Nuñez All rights reserved.

If you have any question, comment or suggestion
about this site, please send us a note

You can help support asp.net.ph