DataTable Copy best practice question

  • Thread starter Thread starter Bill
  • Start date Start date
B

Bill

I use Remoting in my WinForms applications and my forms
usually call some type of GetInitData method of the
Business component that returns a DataSet. The
GetInitData method usually calls classes from my Data
component to populate drop down lists on the form. For
example: Teacher, Subject, ...

The Data components usually have a GetList function which
calls a stored proc and returns a DataTable.

In my Business component, I usually end up adding my
DataTables to one DataSet. It seems like a clean
business function interface this way.

OK, here's the question: Is there another way to add a
DataTable to a DataSet other than using the Copy()
method? Since the DataTables have belonged to another
DataSet via the DataAdapter.Fill, exceptions occur when
using the DataSet.Tables.Add(). I'm concerned with the
performance and memory hit by using Copy().

Thanks in advance for your input,
Bill
 
Hi Bill,
OK, here's the question: Is there another way to add a
DataTable to a DataSet other than using the Copy()
method? Since the DataTables have belonged to another
DataSet via the DataAdapter.Fill, exceptions occur when
using the DataSet.Tables.Add(). I'm concerned with the
performance and memory hit by using Copy().

A lot, but when you can use the copy, there will be probably not one which
is more efficient.

Just my thougt,

Cor
 
The right question to ask is whether you really need the datatable [with
same schema and data] as part of two datasets.

If you do not need the datatable to be part of two datasets, remove the
datatable from one dataset with ds.Tables.Remove and add it to the dataset
where you want it to be.

However, if you want the table to be present in both the datasets, then
datatable.Copy() is the right method to call before inserting it into other
datatable.

HTH,
Ravi
 
Back
Top