by Dominic Zukiewicz
1. February 2008 09:54
I was using DataSet.Merge() to merge rows returned by a SqlDataAdapter into one of the tables.
The scenario was that I was enquiring a specific order/product in the database, and it would Fill() a temporary DataSet with the results. If there were no results, then I just continued. The code was something like:
internal AuditableProduct[] GetAuditableProducts(int[] productIds)
{
DataSet allStatuses = new DataSet();
foreach(int product in productIds)
{
DataSet tempStatus = new DataSet();
SqlConn...
SqlComm.....
SqlDataAdapter da......
da.Fill(tempStatus);
allStatuses.Merge( tempStatus );
}
return ConvertDataSetToAuditableProducts(allStatuses);
}
In my ConvertDataSetToAuditableProducts method, I looped through the rows, using the data to determine its status. The result was that there was 1 row? This seemed odd, as I knew for a fact that many products were auditable and therefore it should be returning more than 1.
The problem is that the .Merge() method merged them into NEW TABLES, instead of seeing that the table schema already existed, therefore creating a new table for each row.
I fixed the problem by merging to DataTable's, not DataSet's.
356aa527-bd9b-41be-948a-01b881935b76|0|.0
Tags:
Framework