Got System.Data.ConstraintException Error on second OleDbDataAdapter filling dataset

Posted on 2005-04-12
Last Modified: 2008-01-09
This looks a very simple project, but I just have no clue why it is not work. Please Help!

I did the things as following:
1. drag to create OleDbDataAdapter1 on form and configure it with Query builder to get data from project table
2. Create dataset DataSet11 from OleDbDataAdapter1
3. drag to create OleDbDataAdapter2 on form and configure it with Query builder to get data from Project Detail Table.
4. Create Dataset DataSet11 from OleDbDataAdapter2
5. Configure the scheme for DataSet11, create relationship between Project table and project detail table
with projectid as keyconstraint.
6. on Form1_load I have code like following:

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        OleDbDataAdapter2.Fill(DataSet11)  <======= Give me the system.Data.ConstraintException Error
    End Sub

It always give me the unhandled exception of type ' Error', with additional information:
Failed to enable constraints. One or more rows contain values viloating non-null, unique, or foreign-key constraints.

Can anyone help me with this? Since I can create a query and run in SQL without any problem.

Please Help!
Question by:Skaugen
    LVL 6

    Expert Comment

    Filling the same dataset without specifying a table name will sometimes attempt to merge the two recordsets being retrieved into a single table thereby causing a constraint violation. Try the following:

    Adapter1.Fill(DataSet11, "Project")
    Adapter2.Fill(DataSet11, "ProjectDetail")

    ... which should attempt to fill your dataset with two tables, one for Projects and one for Project Details.

    LVL 27

    Expert Comment

    Hi Skaugen:
    I suggest you place a breakpoing on the Adapter2 line, and inspect both Adapters using QuickWatch.
    Check their SelectionCommand for example, and see if there is anything there that might give you a clue as to why you are getting an error. YOu might be better off configuring the DataAdapters inside your code, rather than through dragging the adapter onto your form.


    Author Comment

    Thanks for the feedback.

    Havagan's suggestion is not working for me in this case, I am trying to configuring the DataAdapters inside my code to see what happen.

    I am still open to other suggetions if there is any.

    LVL 8

    Accepted Solution

    There is probably an error in trying to build the schema.  You will have to look at the values in the database and see if any don't belong.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Should I Do With This Threat Intelligence?

    Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

    Article by: Kraeven
    Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
    1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
    This video discusses moving either the default database or any database to a new volume.
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    737 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

    20 Experts available now in Live!

    Get 1:1 Help Now