Reputation: 9648
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?
Upvotes: 2
Views: 7279
Reputation: 3094
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;
Upvotes: 2
Reputation: 3517
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
Upvotes: 0
Reputation: 19960
You might want to try;
myDataSet.Tables[0].Select("A = 'xxx'");
Which returns DataRow[]
Upvotes: 1