Link to home
Start Free TrialLog in
Avatar of PastorDwayne
PastorDwayne

asked on

NewRow to DataSet

Good-day,

I have a dataset containing two tables, in a Master-Detail type relationship.  I would like to insert a new row into the child table, but I'm receiving an error "ForeignKeyConstraint RelTables requires the child key values (There) to exist in the parent table".

Here is my code:

******************************************
//DataSet ds
DataRelation relate;
relate = new DataRelation("RelTables", ds.Tables["Parent"].Columns["Col1"], ds.Tables["Child"].Columns["Col1"]);
ds.Relations.Add(relate);

DataRow dr;
dr = Form1.DVM.DataSet.Tables["Child"].NewRow();
dr["Col1"] = "Hello";
dr["Col2"] = "World";

ds.Tables["Child"].Rows.Add(dr);
******************************************

Any suggestions would be appreciated,
Thanks for your time.


ASKER CERTIFIED SOLUTION
Avatar of Jarodtweiss
Jarodtweiss

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I think you need to call SetParentRow