472,799 Members | 1,272 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,799 software developers and data experts.

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


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,

Dec 11 '07 #1
6 2129
7,872 Expert 4TB
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
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.


Dec 11 '07 #3
Bad news ... I tried the following rough and ready code:

Expand|Select|Wrap|Line Numbers
  1. dtbSource.Columns("ID").AutoIncrementSeed = 1
  2. dtbSource.AcceptChanges()
  4. dtbClone = dtbSource.Clone()
  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?


Dec 11 '07 #4
7,872 Expert 4TB
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
don't know if this will work but you could give it a try

Expand|Select|Wrap|Line Numbers
  2. dtClone = dtSource.Clone()
  3. dtClone.Clear()
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
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 :-)

Dec 11 '07 #7

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

Similar topics

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...
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...
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...
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...
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....
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...
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)...
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...
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Sept 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
by: Mushico | last post by:
How to calculate date of retirement from date of birth
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

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.