I make an outer join and executed successfully in the informix
database but I get the following exception in my code:
DataTable dt = TeachingLoadDAL.GetCoursesWithEvalState(i, bat);
Failed to enable constraints. One or more rows contain values violating non-null, unique, or foreign-key constraints.
I know the problem, but I don't know how to fix it.
The second table I make the outer join on contains a composite primary key which are null in the previous outer join query.
EDIT:
SELECT UNIQUE a.crs_e, a.crs_e || '/ ' || a.crst crs_name, b.period,
b.crscls, c.crsday, c.from_lect, c.to_lect,
c.to_lect - c.from_lect + 1 Subtraction, c.lect_kind, e.eval, e.batch_no,
e.crsnum, e.lect_code, e.prof_course
FROM rlm1course a, rfc14crsgrp b, ckj1table c, mnltablelectev d,
OUTER(cc1assiscrseval e)
WHERE a.crsnum = b.crsnum
AND b.crsnum = c.crsnum
AND b.crscls = c.crscls
AND b.batch_no = c.batch_no
AND c.serial_key = d.serial_key
AND c.crsnum = e.crsnum
AND c.batch_no = e.batch_no
AND d.lect_code= e.lect_code
AND d.lect_code = ....
AND b.batch_no = ....
The problem happens with the table cc1assiscrseval
. The primary key is (batch_no, crsnum, lect_code).
How to fix this problem?
EDIT:
According to @PaulStock
advice:
I do what he said, and i get:
? dt.GetErrors()[0] {System.Data.DataRow} HasErrors: true ItemArray: {object[10]} RowError: "Column 'eval' does not allow DBNull.Value."
So I solve my problem by replacing e.eval
to ,NVL (e.eval,'') eval
.and this solves my problem.
Thanks a lot.
Just want to add another possible reason for the exception to those listed above (especially for people who like to define dataset schema manually):
when in your dataset you have two tables and there is a relationship (
DataSet.Reletions.Add()
) defined from first table's field (chfield
) to the second table's field (pfield
), there is like an implicit constraint is added to that field to be unique even though it may be not specified as such explicitly in your definition neither as unique nor as a primary key.As a consequence, should you have rows with repetitive values in that parent field (
pfield
) you'll get this exception too.* Secondary way : *
If you don't need [id] to be as Primary key,
Remove its primary key attribute:
on your DataSet > TableAdapter > right click on [id] column > select Delete key ...
Problem will be fixed.
It sounds like possibly one or more of the columns being selected with:
has AllowDBNull set to False in your Dataset defintion.
If you are using visual studio dataset designer to get the data table, and it is throwing an error 'Failed to Enable constraints'. I've faced the same problem, try to preview the data from the dataset designer itself and match it with table inside your database.
The best way to solve this issue is to delete the table adapter and create a new one instead.