473,503 Members | 2,126 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

VB.NET: DataTable Cloning and Seeds with .NET 2

5 New Member
Hi,

When cloning a DataTable, it appears that seed counts are also copied to the new table e.g. dtbSource has 50 rows, clone dtbSource to dtbClone and then add the first new row to dtbClone ... this new row will have an "ID" of 51 rather than 1. Setting AutoIncrementSeed on dtbClone has no effect whatsoever. In actual fact I have tried multiple variations of AutoIncrementSeed and AutoIncrementStep including:

Expand|Select|Wrap|Line Numbers
  1. dtbClone.Columns("ID").AutoIncrementStep = -1
  2. dtbClone.Columns("ID").AutoIncrementSeed = -1
  3. dtbClone.Columns("ID").AutoIncrementStep = 1
  4. dtbClone.Columns("ID").AutoIncrementSeed = 1
... but nothing seems to have the desired effect. All I want is dtbSource to carry on from the point of cloning e.g. 51, 52 etc. and dtbClone to start from 1.

Thanks in advance for any insight,

Rod.
Dec 11 '07 #1
6 2172
Plater
7,872 Recognized Expert Expert
Clone claims to copy over all formatting data too right, that's what is causing the problem?
Could you get away with changing the autoincrement stuff on the source, make the clone, then turn the auto increment stuff back ON on the source?
Dec 11 '07 #2
rclarke
5 New Member
Thanks for the quick response. That certainly is an interesting approach, and not one that I had thought of. I can give it a try and get back to you.

Thanks,

Rod.
Dec 11 '07 #3
rclarke
5 New Member
Bad news ... I tried the following rough and ready code:

Expand|Select|Wrap|Line Numbers
  1. dtbSource.Columns("ID").AutoIncrementSeed = 1
  2. dtbSource.AcceptChanges()
  3.  
  4. dtbClone = dtbSource.Clone()
  5.  
  6. dtbSource.Columns("ID").AutoIncrementSeed = 1000
  7. dtbSource.AcceptChanges()
... and although dtbSource then started counting from 1000, dtbClone continued counting from the original row count of dtbSource rather than 1. Something tells me you can't wind the seed back when the Unique property is set to True, you can only send it forward.

Any other thoughts?

Thanks,

Rod.
Dec 11 '07 #4
Plater
7,872 Recognized Expert Expert
Hmm, what are you going to do with the clone?
Could you maybe delete/recreate the column? That might make the counter start at one.
Dec 11 '07 #5
demaus
6 New Member
don't know if this will work but you could give it a try

Expand|Select|Wrap|Line Numbers
  1.  
  2. dtClone = dtSource.Clone()
  3. dtClone.Clear()
  4.  
haven't tried this in code myself, I know that .Clear() will remove data and maybe it will reset the increment?.
Dec 11 '07 #6
rclarke
5 New Member
Good call Plater ... I am beginning to think that deleting and then recreating the column might be the simplest way out of this predicament. I will try that next.

Incidentally, the purpose of the Clone is to act as multi-row Cut, Copy & Paste clipboard for the Source. I'm not sure whether that changes anything, but it seems to be the most efficient approach.

Many thanks for the suggestion demaus. I omitted to mention in my first post that I had also tried the Clear method, but to no avail, but thanks anyway :-)

Rod.
Dec 11 '07 #7

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

Similar topics

3
1711
by: AVL | last post by:
Hi, I've a query in cloning. How cloning is different from creating a new instance of an object.? I suppose cloning also creates a new object and copies the exisitng object's data. Where and when...
3
5978
by: Coleen | last post by:
Hi all :-) I have a datatable that I need to clone completely except for 1 column - I need to replace the contents of this 1 column with the contents from another datatable that has the exact...
4
4942
by: hharry | last post by:
hello all, i have 2 datatables and am trying to transfer rows from datatable a to datatable b i use the datatable.importrow method. the importrow method fails (but does not throw an...
2
4271
by: neilr | last post by:
Can anyone help with some problkems that have wasted 2 days of my (inexperienced) time already? We have a website which allows people to register for events like conferences We are importing...
6
5890
by: Intiha | last post by:
Hello all, I am trying to generate random seeds for my simulations. currently i was using srand(time(NULL); for this purpose. But for confidence in my results i ran it using a script in a loop....
2
6925
by: Jobs | last post by:
Download the JAVA , .NET and SQL Server interview with answers Download the JAVA , .NET and SQL Server interview sheet and rate yourself. This will help you judge yourself are you really worth of...
7
3837
by: Wayne Gibson | last post by:
Hi All, Was wondering if anybody could help. I'm currently trying to copy a record from datatable to another. I have two problems: 1) Transferring the record from one datatable to another. 2)...
1
1770
by: Dan Dorey | last post by:
I've implemented the ICloneable interface on one of my class. I've written this simple code in two different ways and I think both should work but it's not the case and I'm curious to understand...
0
7205
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,...
0
7093
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7468
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...
1
5023
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...
0
4689
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...
0
3180
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3170
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
747
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
401
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...

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.