473,657 Members | 2,414 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 AutoIncrementSe ed on dtbClone has no effect whatsoever. In actual fact I have tried multiple variations of AutoIncrementSe ed and AutoIncrementSt ep 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 2190
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
1718
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 should use cloning????//
3
6014
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 same number of rows. I've tried using Removeat to remove the column, but when I try to add the column back in, it does not work. All I want to do is overwrite the data that is there with the new data. Any suggestions? Here is a snippet of the...
4
4955
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 exception) when importing a datarow that has numeric columns. columns of type string are imported fine.
2
4279
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 a table of fees for the apporpriate event using an Sp: FeesDataSet = New System.Data.DataSet Dim MySPcommand As New System.Data.SqlClient.SqlCommand MySPcommand.CommandText = "SP4105201getWebFeeTable"
6
5904
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. Since the time b/w execution is very similar, many simulation runs resulted in exact same results. Is there a better way of seeding the random number generator in c/c++
2
6948
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 attending interviews. If you own a company best way to judge if the candidate is worth of it. http://www.questpond.com/InterviewRatingSheet.zip
7
3846
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) Transferring the record from the new datatable back to the database. Any ideas? Thanks
1
1777
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 why. The working method: CallflowBase ret = null; ret = this.MemberwiseClone() as CallflowBase; ret.m_callflowName = this.m_callflowName;
0
8315
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8829
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8734
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8608
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...
0
7341
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5633
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
4323
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1962
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1627
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.