Fog Creek Software
Discussion Board

Welcome! and rules

Joel on Software

DataAdapter Fill() method doens't refresh!

Ok, I have a dataset, and I need it to be "refreshed".  When I call the same method twice, it puts a duplicate row into the dataset.  In the description of the Fill method in DataAdapter says "fills or refreshes".  Is it possible for the dataadapter to "know" that the rows are allready there, and either update them or leave them be?

Vincent Marquez
Wednesday, July 02, 2003

At a guess, you didn't tell the DataSet which column is the PK of the table. From the help for DbDataAdapter.Fill(DataSet):

When using subsequent Fill calls to refresh the contents of the DataSet, two conditions must be met:

1. The SQL statement should match the one initially used to populate the DataSet.
2. The Key column information must be present.

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

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 a Primary Key for a Table.

Mike Gunderloy
Wednesday, July 02, 2003

*  Recent Topics

*  Fog Creek Home