DataSet contains duplicate records based on the SQL outer join query (317058)
The information in this article applies to:
- Microsoft ADO.NET (included with the .NET Framework) 1.0
- Microsoft ADO.NET (included with the .NET Framework 1.1)
- Microsoft ADO.Net 2.0
- Microsoft Visual Basic .NET (2002)
- Microsoft Visual Basic .NET (2003)
- Microsoft Visual Basic 2005
This article was previously published under Q317058
This article refers to the following Microsoft .NET Framework Class Library namespaces:
- System.Data
- System.Data.SqlClient
SYMPTOMS
If you call the Fill method of the DataAdapter object twice on a DataTable in a DataSet that is based on a SQL outer join statement, if you do not first clear the current contents of the DataTable, the DataTable may contain two copies of each record.
CAUSE
The records are duplicated because a DataTable that is based on a SQL outer join query does not contain primary key information to identify each record uniquely. Instead of merging with the existing records based on key information, a second set of exactly the same records is appended.
RESOLUTION
To resolve this problem, clear the DataTable before you reload the data. To do this, call the Clear method of the DataTable or the DataSet before you call the Fill method of the DataAdapter the second time.
This is the recommended method. This method is more efficient than if you require the DataAdapter to merge the new data with the existing data.
STATUSThis behavior is by design.
Modification Type: | Minor | Last Reviewed: | 10/3/2006 |
---|
Keywords: | kbtshoot kbDataAdapter kbprb kbSqlClient kbSystemData KB317058 kbAudDeveloper |
---|
|