Copy a dataset to a new dataset with new records

  • Thread starter Thread starter Ritesh Jain via DotNetMonster.com
  • Start date Start date
R

Ritesh Jain via DotNetMonster.com

Hi,

Try with this........


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

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

Regards,
Ritesh
 
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
 
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.
}
}
 
There's a bulk copy command with ADO.NET 2.0



Trygve said:
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
 
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!
 
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
 
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 said:
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.........??
 
Back
Top