Master detai problem

Posted on 2004-11-05
Last Modified: 2010-04-23
I have a search combobox,  on a master detail form.

dataset 1 has two datatables and a relation linking them through primary key and forigen key.

The parent in this relationship has a parameter in its Sql statement, it uses the selected value form the cocombox to fill the datatable, The problem is that the child table fills with all the record from its dataAdapter then it has an error,  "The dataset is violating the forign key constraint".  Im assuming this is because it is retreiving all the child records instead of just the ones for the parent.

Help!  Do i need to set the child with a parameter two?

Question by:Nerdy_Girl88
    LVL 2

    Expert Comment

    Can you try passing "False" parameter when you create a datarelation? By default, ADO .NET enforces constraints.

    LVL 2

    Expert Comment

    something like

    dr= New DataRelation("relationName", datacol1, datacol2, False)
    LVL 8

    Accepted Solution

    Are you using one data adapter to fill both tables? If so, due to the way the select command works with the data adapter, you should use TWO data adapters. One to fill the parent table, and the other to fill only the child table.

    Another suggestion, if I may, is to fill both tables, the master and the details table first, and THEN add the relation object to the database. If there is no exception when the relation is added to the dataset, then that's gravy. If not, then there is something wrong with teh select statement, and I would suggest verifying that the WHERE clause is selective enough for the pk fk constraint.

    If you get this far, then

    1. Bind the master grid 's datasource to the dataset, and the datamember to the name of the table.

    2. Bind the details grid's datasource to the dataset, and the datamember to the name of the relation object.

    Here is an MSDN article about this Master Details fun for your reference:

    Good luck with your project.

    Featured Post

    Highfive Gives IT Their Time Back

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
    Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
    Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
    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.

    734 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

    22 Experts available now in Live!

    Get 1:1 Help Now