468,133 Members | 1,222 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,133 developers. It's quick & easy.

How to copy a DataTable?

Hey guys,

In my app, I have a DataTable named "dta"...

If i create a new variable of DataTable type named "dta2", and assign
the dta as value, it creates a reference to dta, then, when I make
changes in dta, dta2 is also changed...

For example:

DataTable dta2;
dta2 = dta;

(now, if I change dta, dt2 will be changed to)..

I'd like to know how to create a "copy" of "dta" (copy the structure
and data), so, when I need to change dta, dta2 will keep the original
data...

I want another instance of the dataTable, with the same structure and
data of the "copied"...

can anybody help-me?

Sep 22 '06 #1
4 4999
When doint DataTable dta2 = dta; you are acutally copying the refernce to
the original instance.

To copy the actual object, use the clone method.

DataTable copied = dta.Clone();

now copied references a new object which is equal to the original dta but is
not the same.

"Férnas" <ga*****@wideweb.com.brwrote in message
news:11**********************@h48g2000cwc.googlegr oups.com...
Hey guys,

In my app, I have a DataTable named "dta"...

If i create a new variable of DataTable type named "dta2", and assign
the dta as value, it creates a reference to dta, then, when I make
changes in dta, dta2 is also changed...

For example:

DataTable dta2;
dta2 = dta;

(now, if I change dta, dt2 will be changed to)..

I'd like to know how to create a "copy" of "dta" (copy the structure
and data), so, when I need to change dta, dta2 will keep the original
data...

I want another instance of the dataTable, with the same structure and
data of the "copied"...

can anybody help-me?

Sep 22 '06 #2
..Clone() copies the structure alone. .Copy() copies the structure and data.

Ciaran O'Donnell
"FĂ©rnas" wrote:
Hey guys,

In my app, I have a DataTable named "dta"...

If i create a new variable of DataTable type named "dta2", and assign
the dta as value, it creates a reference to dta, then, when I make
changes in dta, dta2 is also changed...

For example:

DataTable dta2;
dta2 = dta;

(now, if I change dta, dt2 will be changed to)..

I'd like to know how to create a "copy" of "dta" (copy the structure
and data), so, when I need to change dta, dta2 will keep the original
data...

I want another instance of the dataTable, with the same structure and
data of the "copied"...

can anybody help-me?

Sep 22 '06 #3
Hey Lebesgue, thanks for your reply...

Is there a method to copy the data of the datatable too... I need the
data, not just de structure and the clone method gives me just the
structure...

thanks!

"I NEED THE STRUCTURE AND DATA PEOPLE"...

thanks...

Lebesgue escreveu:
When doint DataTable dta2 = dta; you are acutally copying the refernce to
the original instance.

To copy the actual object, use the clone method.

DataTable copied = dta.Clone();

now copied references a new object which is equal to the original dta butis
not the same.

"Férnas" <ga*****@wideweb.com.brwrote in message
news:11**********************@h48g2000cwc.googlegr oups.com...
Hey guys,

In my app, I have a DataTable named "dta"...

If i create a new variable of DataTable type named "dta2", and assign
the dta as value, it creates a reference to dta, then, when I make
changes in dta, dta2 is also changed...

For example:

DataTable dta2;
dta2 = dta;

(now, if I change dta, dt2 will be changed to)..

I'd like to know how to create a "copy" of "dta" (copy the structure
and data), so, when I need to change dta, dta2 will keep the original
data...

I want another instance of the dataTable, with the same structure and
data of the "copied"...

can anybody help-me?
Sep 22 '06 #4
Use the Copy method then.

"Férnas" <ga*****@wideweb.com.brwrote in message
news:11*********************@i3g2000cwc.googlegrou ps.com...
Hey Lebesgue, thanks for your reply...

Is there a method to copy the data of the datatable too... I need the
data, not just de structure and the clone method gives me just the
structure...

thanks!

"I NEED THE STRUCTURE AND DATA PEOPLE"...

thanks...

Lebesgue escreveu:
When doint DataTable dta2 = dta; you are acutally copying the refernce to
the original instance.

To copy the actual object, use the clone method.

DataTable copied = dta.Clone();

now copied references a new object which is equal to the original dta but
is
not the same.

"Férnas" <ga*****@wideweb.com.brwrote in message
news:11**********************@h48g2000cwc.googlegr oups.com...
Hey guys,

In my app, I have a DataTable named "dta"...

If i create a new variable of DataTable type named "dta2", and assign
the dta as value, it creates a reference to dta, then, when I make
changes in dta, dta2 is also changed...

For example:

DataTable dta2;
dta2 = dta;

(now, if I change dta, dt2 will be changed to)..

I'd like to know how to create a "copy" of "dta" (copy the structure
and data), so, when I need to change dta, dta2 will keep the original
data...

I want another instance of the dataTable, with the same structure and
data of the "copied"...

can anybody help-me?

Sep 23 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Brian Bischof | last post: by
reply views Thread by Kelvin | last post: by
3 posts views Thread by Gene Hubert | last post: by
reply views Thread by mikejacobz | last post: by
27 posts views Thread by didacticone | last post: by
1 post views Thread by gcdp | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.