Ehud Grand
Ehud Grand

Reputation: 3693

c# DataSet Cannot make this change because constraints are enforced on relation XXX, and changing this value will strand child rows

I have a DataSet with few tables, 2 of them are related in Conatraint in the XSD file.

When I save (update with the data adapter) the parent table I get this error:

Cannot make this change because constraints are enforced on relation XXX, and changing this value will strand child rows.

XXX is the relation in the XSD file.

I simply don't understand what is this, I've tried google but nothing.

The parent table id is connected with FK to a column in the child table and saving the parent table should update the child.

I don't understand this error, please help.

EDIT:

The code that creates new row in the child table MyDataSet.Patient_IVFOocytesFreezeOocytesInGroups:

                    // connect the oocytes with a group
                    IVFOocyteManagerDataset.Patient_IVFOocytesFreezeOocytesInGroupsRow newgrouprow = MyDataSet.Patient_IVFOocytesFreezeOocytesInGroups.NewPatient_IVFOocytesFreezeOocytesInGroupsRow();

                    if (selectedStraws.Count == 1)
                    {
                        int g = MyDataSet.Patient_IVFOocytesFreezeStraw.Where(x => x.IsSelecetd == true).Select(x => x.group_id).FirstOrDefault();
                        newgrouprow.group_id = MyDataSet.Patient_IVFOocytesFreezeGroups.Where(x => x.group_id == g).Select(x => x.group_id).SingleOrDefault();

                        OocyteStraws.Rows[i].StrawDisplayId = MyDataSet.Patient_IVFOocytesFreezeStraw.Where(x => x.IsSelecetd == true).Select(x => x.display_id).FirstOrDefault();
                    }
                    else
                    {                           
                        OocyteStraws.Rows[i].StrawDisplayId = -1;
                        newgrouprow.group_id = selectedStraws.Select(x => x.group_id).FirstOrDefault();
                    }

MyDataSet.Patient_IVFOocytesFreezeGroups is the parent table.

Upvotes: 2

Views: 658

Answers (2)

Ehud Grand
Ehud Grand

Reputation: 3693

Well, after few hours I found the answer:

In the DataSet Designer, the reltaion wasn't Cascade. Tha'ts all.

Upvotes: 2

hawkstrider
hawkstrider

Reputation: 4341

Are you changing the ID value on the parent table or is it an auto generated identity? You really shouldn't be changing it in the update.

Can you post your data models and the updating code that you are using so that it is easier to see what is going on?

Upvotes: 0

Related Questions