DataSet.Merge() didn't merge tables correctly.

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.

Tags:

Framework

Powered by BlogEngine.NET 1.5.0.7
Theme by Interakting

Interakting

A full service digital agency offering online strategy, design and usability, systems integration and online marketing services that deliver real business benefits and ensure your online objectives are met.

Calendar

<<  February 2012  >>
MoTuWeThFrSaSu
303112345
6789101112
13141516171819
20212223242526
2728291234
567891011

View posts in large calendar