?
Solved

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

Posted on 2005-04-12
4
Medium Priority
?
775 Views
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
        OleDbDataAdapter1.Fill(DataSet11)
        OleDbDataAdapter2.Fill(DataSet11)  <======= Give me the system.Data.ConstraintException Error
    End Sub

It always give me the unhandled exception of type 'system.data.constraintException 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!
0
Comment
Question by:Skaugen
4 Comments
 
LVL 6

Expert Comment

by:Havagan
ID: 13766635
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.

Paul
0
 
LVL 27

Expert Comment

by:Dabas
ID: 13766766
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.

Dabas
0
 

Author Comment

by:Skaugen
ID: 13767118
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.

Thanks
0
 
LVL 8

Accepted Solution

by:
rodmjay earned 750 total points
ID: 13768580
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.
0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

Question has a verified solution.

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

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses
Course of the Month16 days, 18 hours left to enroll

864 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