How to copy ds row to a new row in same ds?

are you giving it a new primary key value?
or are you not saving the new row back to the database?
why do you want repeat the information in the dataset?
ailzaj
 
You should be able to just create a new DataRow for your table then copy the data from the existing DataRow to the new one, then insert the new DataRow into your table.
 
copy row of table in ds to same table

The table in the data set represents a contract that can be amended at a later date. If amended, I need another row in the table with a different effective date. The user will then change the price, voulme, location or whatever changed to cause the amendment. I need both versions of the contract in the table since schedulers work with the data in the future months and accounting works with the data in the prior month. ( No one works with the data in the current month.)

I have tried the following:

Dim nr as datarow = ds.tables(0).rows(0)

... change the key field effective date

ds.tables(0).rows.add(nr)

This produces an error stating the row already exists in the table, apparently because the row number is the same. The key field was changed.

Could you explain more about the copy and copyto methods? The copyto method copies the row to an array (I think), but how do you copy the array back to a row?

Thanks for the responses.
 
Please post the exact error message.

If your primary key is the same, or if your db fields are set up as unique, you wont be able to recreate that datarow by any method. i.e. its not a procedural code issue, it is a db restriction.

Jon
 
If you are dealing with historical data then try adding extra fields on the original row for the updated information, if thats not going
to work you may have to consider setting up a seperate table for
the new contract information.

ailzaj
 
Last edited by a moderator:
Futher info

There are no unique columns defined in the table other than the primary key, which was changed. The error message is "This row already exists in table."

The following code works:

dim nr as datarow = ds.tables(0).rows.newrow

With ds,tables(0).rows(0)
nr("ContNo") = .Item("ContNo")
nr("EffDate") = NewDate
nr("Cont_Class") = .Item("Cont_Class")
nr("Cont_Type") = .Item("Cont_Type")
.
.
.
End with
ds.tables(0).rows.add(nr)


I was just trying to find a way to add the row without coding a line for each column. The contract consists of 4 tables, each with at least 40 columns. I have decided to code the 160 lines or so, just to keep moving.

The copy method apparently copies data about the row in addition to the columns. I am sure this additional data is causing the above error message. The debugger shows many fields for a table and row in addition to the column values.

Thanks again for the responses.
 
Back
Top