Solved

NewRow to DataSet

Posted on 2004-03-28
2
775 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

920 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now