Solved

NewRow to DataSet

Posted on 2004-03-28
2
774 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
Comment Utility
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
Comment Utility
I think you need to call SetParentRow
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

762 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

10 Experts available now in Live!

Get 1:1 Help Now