Add child rows to a datatable that have a data relation

E

Earl

I've been struggling with this data relation issue for awhile now. I've
found the source of the problem, but am unsure how to resolve this so I can
get the functionality I need. This would seem to be very common
functionality, but I do not see how it is done. Yes, I could just populate
the datagrid using an additional call back to the server with a JOIN, but
surely two trips to the server for the same data is not how the disconnected
motif of .Net is supposed to be implemented!

Fundamentally, it appears that what I'm trying to do is add rows to a table
where 3 of the columns are read-only, since they were added from the Parent
table to the child table. Thus an exception is raised on Update. Here I add
the 3 columns from the parent table to the child table and then later try to
Update the suppliers table.

I think my distilled question becomes: do I need to drop these columns from
the supplier table before doing the Update? If so, how? Is there a different
syntax for applying the Update to the child table? Or is there a way to make
those columns not read-only so it will accept the Update?

relSuppliers = New DataRelation("CityStateZipSupplier", _
dsWinMatrix.Tables("dtSupplierZips").Columns("ZipCityStateID"), _
dsWinMatrix.Tables("dtSuppliers").Columns("SupplierZipCityID"), False)
dsWinMatrix.Relations.Add(relSuppliers)

dsWinMatrix.Tables("dtSuppliers").Columns.Add("City", GetType(String),
"Parent(CityStateZipSupplier).City")
dsWinMatrix.Tables("dtSuppliers").Columns.Add("State", GetType(String),
"Parent(CityStateZipSupplier).State")
dsWinMatrix.Tables("dtSuppliers").Columns.Add("Zip", GetType(String),
"Parent(CityStateZipSupplier).Zip")

.....

da.Update(dsChanges, "dtSuppliers")
 
K

Kevin Yu [MSFT]

Hi Earl,

First of all, I would like to confirm my understanding of your issue. From
your description, I understand that you still cannot update the changes in
your DataSet to database. If there is any misunderstanding, please feel
free to let me know.

When updating, we needn't drop the columns with expression. I have also
tried it on my machine, however, I cannot reproduce this issue. If your
update command is set correctly, I think no exception will be thrown. Did
you tried my suggestion to check for the DataAdapter.RowUpdating event to
see which row update operation throws the exception?

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 
E

Earl

Yes I did. All it gave me was the status. It was failing OnUpdated. But I
found no other way to resolve the issue without dropping the parent rows
right before Update.
 
K

Kevin Yu [MSFT]

Hi Earl,

If you could send me a repro package, it would be more quickly for me to
debug on it. Remove 'online' from the no spam email address above is my
real email.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 
E

Earl

Kevin, this issue has been resolved to the extent that the only solution I
found was to drop the child columns prior to Insert and then re-add the
columns immediately thereafter to the datatable. If there is an alternative
solution, I would be interested in implementing it, but for now, this is the
only solution I've found. I previously sent you a copy of the form class.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top