473,803 Members | 3,030 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Copy / Clone DataTable?

nev
251 Contributor
I have a datatable dtt1 with data in it. It is bind to bs1

Then I do...

dtt2 = dtt1.copy

Thinking that I will be able to manipulate dtt2 without affecting dtt1...

I assign a bindingsource bs2.datasource = dtt2

But when I manipulate bs2, for example sorted it, bs1 also gets sorted. What's the problem here?

Anybody knows how I can manipulate bs2 without affecting bs1???
Oct 15 '07 #1
4 1780
nev
251 Contributor
I tried this but the result is still the same

bs1 is binded to dtt1

dtt2 = dtt1.clone

For i As Integer = 0 To dtt1.Rows.Count - 1
dtt2.ImportRow( dtt1.Rows(i))
Next

bs2.datasource = dtt2

When I sort bs2, bs1 still gets sorted also.
Oct 15 '07 #2
nev
251 Contributor
I got it myself... here, I'll share it.

dtt2.clear()

dtt2.merge(dtt1 )

bs2.datasource = dtt2

Any manipulation done to bs2 is reflected only to bs2.

Thanks for all those who helped :-)
Oct 15 '07 #3
chandru8
145 New Member
hi
can you please explain the code you are doing...
Oct 15 '07 #4
nev
251 Contributor
The code I'm trying to do is to find a faster way to copy data from one datatable to another without the bind compared to using a loop.
Oct 15 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

2
9148
by: Dianna K. | last post by:
I have a dataview which I am assigning to a Datatable (I am doing this because currently Crystal Reports will not accept a dataview as a Reportsource -- The recommended work-around is to assign dataview to datatable). The dataview is being filtered. However when I assign it to the datatable it is not filtered. I put some debug code in and the Dataview has 8 records then I assign it to a new datatable. When I check the row count of the...
42
5813
by: Edward Diener | last post by:
Coming from the C++ world I can not understand the reason why copy constructors are not used in the .NET framework. A copy constructor creates an object from a copy of another object of the same kind. It sounds simple but evidently .NET has difficulty with this concept for some reason. I do understand that .NET objects are created on the GC heap but that doesn't mean that they couldn't be copied from another object of the same kind when...
3
4740
by: Matthew Wieder | last post by:
I have a datatable as a source and I need to produce a datatable which is all the rows in the original datatable except the first row, copied n times. So, if I had a datatable of: A B C 1 21 12 32 2 1 43 12 3 32 12 35 I need to output:
0
5833
by: Kelvin | last post by:
Hi All, Due to can't insert new row between row and row while current DataTable looping. In order to solve the problem, I need to clone it as new DataTable, while the DataTable Looping, it also insert both of new row and existing datarow into new DataTable, but I don't know how to do that, Here is my souce code, Please advise. if ( myTable.Rows.Count > 0 )
2
13337
by: JC Voon | last post by:
Hi: What is the best way to copy the schema of one DataTable to another ?, The DataTable.Clone will create a new DataTable Currently i do it manually destTable.Clear() destTable.Columns.Clear() destTable.Constraints.Clear()
5
38764
by: Katit | last post by:
I get dataset from database. I need to take specific datatable out of it and add it to second dataset to pass back from webservice. ds.Tables.Add(dsPart.Tables); I get exception "Datatable already belongs to another dataset" Which is true :) But why can't I do that? TIA
4
5167
by: Férnas | last post by:
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:
3
24690
by: Manuel | last post by:
Hi to all, I'm trying to copy a Datacolumn from a table to another, but with this code: destTable.Columns.Add(srcTable.Column); I got this error: Column 'colname' already belongs to another DataTable. Anyone can help me?
0
9700
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
1
10292
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10068
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7603
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6841
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5627
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4275
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3796
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2970
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.