views:

2515

answers:

3

I have one DataSet that contain 2 relate DataTable (master and details). I want to copy data that match my filter (e.g. master data column A = "XXX") to another DataSet.

Now I found that this process take a very very long time. (about one hour for 1k records)

I want to know how to improve this processing time?

Thanks, Ek

+1  A: 

You might want to try;

 myDataSet.Tables[0].Select("A = 'xxx'");

Which returns DataRow[]

Dead account
A: 

You might gain some benefit in outlining your problem in greater detail - there may be a better option then duplicating your data.

If you really want to go down this path you may want to take a look at the DataView class:

http://msdn.microsoft.com/en-us/library/system.data.dataview.aspx

This will allow you to extract data based on a filter from a datatable. The DataView also has a method ToTable:

http://msdn.microsoft.com/en-us/library/system.data.dataview.totable.aspx

This will return a datatable, based on the selected rows in the DataView.

This should perform better then your version, although I am not sure if other options will provide faster implementations again. I believe the above DataTable.Select will perform better then the DataView

Chris
+2  A: 

I'd say copy-ing 1000 records should only take a few milliseconds. Make sure there are no events firing or databindings doing strange things.. Maybe you should try without the relations but I believe enforcecontraints=false also disable foreign key checking..

The following code copies a complete dataset quite fast:

fDstDataSet.EnforceConstraints = false;
foreach (DataTable fSrcTable in fSrcDataSet.Tables)
{
    DataTable fDstTable = fOpenOrders.Tables[fSrcTable.TableName];
    foreach (DataRow fSrcRow in fSrcTable.Rows)
    {
        fDstTable.ImportRow(fSrcRow);
    }
}
fDstDataSet.EnforceConstraints = true;
Julian de Wit
EnforceConstraints on a DataSet like that is only the constraint of the in memory dataset, not back to the actual database constraints. If you have a simple table filled from a DataAdapter there are usually no constraints present.
Jason Short