Solved

NewRow to DataSet

Posted on 2004-03-28
2
779 Views
Last Modified: 2012-06-27
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.


0
Comment
Question by:PastorDwayne
2 Comments
 
LVL 4

Accepted Solution

by:
Jarodtweiss earned 100 total points
ID: 10697884
You have set a relation between "Col1" of parent table and of child table
And you are trying to set the value "Hello" in Child Col1 table
Are you sure that this value "Hello" exist in the Col1 of parent table ?
0
 
LVL 10

Expert Comment

by:ptmcomp
ID: 10699089
I think you need to call SetParentRow
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question