PC Review


Reply
Thread Tools Rate Thread

Copy a dataset to a new dataset with new records

 
 
Ritesh Jain via DotNetMonster.com
Guest
Posts: n/a
 
      18th Jan 2005
Hi,

Try with this........


Dim dsNew As DataSet
dsNew = oldDataSet.GetChanges(DataRowState.Added)

I hope this will help u............

Regards,
Ritesh

--
Message posted via http://www.dotnetmonster.com
 
Reply With Quote
 
 
 
 
Ritesh Jain via DotNetMonster.com
Guest
Posts: n/a
 
      18th Jan 2005
Hi,
I don't know what exactly u want to achieved but it would be better if u tell me why can't u used that same dataset to save the Rows in Database....as it has all the Row state in tag.........??

Regards,
Ritesh

--
Message posted via http://www.dotnetmonster.com
 
Reply With Quote
 
W.G. Ryan eMVP
Guest
Posts: n/a
 
      18th Jan 2005
Ritesh - if the rowstate is different in the source - other than added, I
think you're best bet is to foreach(TypeDataRow dro in TypeDataSetRows){

foreach(TypedColumn in columns){
Newrow --- add the values here.
}
}

--
W.G. Ryan MVP (Windows Embedded)

TiBA Solutions
www.tibasolutions.com | www.devbuzz.com | www.knowdotnet.com
"Ritesh Jain via DotNetMonster.com" <(E-Mail Removed)> wrote in
message news:(E-Mail Removed)...
> Hi,
>
> Try with this........
>
>
> Dim dsNew As DataSet
> dsNew = oldDataSet.GetChanges(DataRowState.Added)
>
> I hope this will help u............
>
> Regards,
> Ritesh
>
> --
> Message posted via http://www.dotnetmonster.com



 
Reply With Quote
 
The God's Awful Truth
Guest
Posts: n/a
 
      19th Jan 2005

There's a bulk copy command with ADO.NET 2.0



Trygve Lorentzen wrote:
> Hi,
>
> I want to take all the data in an existing typed dataset (with existing data
> in the underlying database) and copy these data to a new typed dataset,
> except all the rows should be new rows.
>
> My guess is that Dataset.Copy() would not work here since it gives me an
> exact copy of the dataset. Will I have to loop through each DataRow in each
> DataTable in the dataset and copy that DataRow to a new and empty DataSet
> with the same structure? If so, how do I maintain referential integrity?
>
> Any ideas, links, suggestions how to do this? All help will be greatly
> appreciated!
>
>



--
incognito...updated almost daily
http://kentpsychedelic.blogspot.com

Texeme Textcasting Technology
http://texeme.com

 
Reply With Quote
 
Trygve Lorentzen
Guest
Posts: n/a
 
      20th Jan 2005
Hi,

I want to take all the data in an existing typed dataset (with existing data
in the underlying database) and copy these data to a new typed dataset,
except all the rows should be new rows.

My guess is that Dataset.Copy() would not work here since it gives me an
exact copy of the dataset. Will I have to loop through each DataRow in each
DataTable in the dataset and copy that DataRow to a new and empty DataSet
with the same structure? If so, how do I maintain referential integrity?

Any ideas, links, suggestions how to do this? All help will be greatly
appreciated!


 
Reply With Quote
 
Trygve Lorentzen
Guest
Posts: n/a
 
      20th Jan 2005
Hi and thanks for your answer!

I need to copy all rows, not just added rows from the original dataset. But
in the new dataset all copied rows must have status as added so that they
are written to the database as new records. Perhaps I haven't managed to
explain what I need to accomplish very well, hope this helps. Below is an
example:

Original DataSet with one table with one row:

dsOrig
->tblTest
->rows[0]
-> colID = 63 (autoinc column)
-> colName = 'Test'

will be copied to a new dataset like this:
dsNew
->tblTest
->rows[0]
-> colID = -1 (autoinc column, column is set to start new
records at -1 and increment new rows by -1, hence the first row will be -1)
-> colName = 'Test'

Well, as far as I can tell I need to go through all the tables and all the
rows in the original dataset and copy the data over row by row and set
parentrow to the correct parentrow to maintain referential integrity.

Maybe another solution is to use DataSet.Copy and then modify the values of
the primary keys (autoinc) columns to new values and set each rows rowstate
to added? Is this even possible?

What do you guys think?

Sincerely,
Trygve

"Ritesh Jain via DotNetMonster.com" <(E-Mail Removed)> wrote in
message news:(E-Mail Removed)...
> Hi,
>
> Try with this........
>
>
> Dim dsNew As DataSet
> dsNew = oldDataSet.GetChanges(DataRowState.Added)
>
> I hope this will help u............
>
> Regards,
> Ritesh
>
> --
> Message posted via http://www.dotnetmonster.com



 
Reply With Quote
 
Trygve Lorentzen
Guest
Posts: n/a
 
      21st Jan 2005
Maybe that is another possible idea. I'll try once more to explain what I
want. I have a certain structure in a DB with one parent row and several
child rows, this structure is the data for a form in the user interface. If
one could view that record structure as a word document I want a
functionality just like "Save As", to save the document to a new file, but
with a different filename. In other words I want to duplicate a certain
related structure of data in the database. The only thing that must be
changed is the primary key of the parent record and the related table(s)
foreign key (in a .NET dataset, it's ParentRow property must be set to the
correct parent row). The child row(s) primary key must also be new values of
course.

I hope this cleared things up, I have a hard time explaining it better.

Regards,
Trygve

"Ritesh Jain via DotNetMonster.com" <(E-Mail Removed)> wrote in
message news:(E-Mail Removed)...
> Hi,
> I don't know what exactly u want to achieved but it would be better if u

tell me why can't u used that same dataset to save the Rows in
Database....as it has all the Row state in tag.........??
>
> Regards,
> Ritesh
>
> --
> Message posted via http://www.dotnetmonster.com



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Copy large data from one dataset to another dataset mina Microsoft VB .NET 1 1st Sep 2009 08:19 PM
The difference between DataSet.GetChanges and DataSet.Copy A.M Microsoft ADO .NET 2 23rd Feb 2005 03:08 AM
RE: Copy DataSet to Type Dataset David Sceppa Microsoft ADO .NET 1 20th Aug 2003 04:18 PM
Re: Copy DataSet to Type Dataset Mark Keogh Microsoft ADO .NET 0 19th Aug 2003 10:55 PM
Re: copy/move rows from a dataset to another dataset? Stephen Muecke Microsoft ADO .NET 1 22nd Jul 2003 04:56 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:10 AM.