Solved

NewRow to DataSet

Posted on 2004-03-28
2
780 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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

685 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