Consider an SQL Server table containing:
ID ParentID Text
=== ========= =============
1 (null) Product
2 (null) Applications
3 1 Background
4 1 Details
5 2 Mobile
i fill a SqlDataSet with the table, and now i want to add the Parent-Child relation to the DataSet:
public DataRelation(
string relationName,
DataColumn parentColumn,
DataColumn childColumn,
bool createConstraints
)
Now this guy uses:
DataRelation relation = newDataRelation("ParentChild",
ds.Tables[0].Columns["ID"], //parentColumn
ds.Tables[0].Columns["ParentID"] //childColumn,
true //createConstraints
);
But when i do that i get the exception:
This constraint cannot be enabled
as not all values have corresponding parent values.
People have suggested passing false for createConstraints
; but then why does it work for him?
And what is a child and what is a parent anyway? i would have thought the child column is the column that needs pointing to a parent, and parent column is the thing that does the pointing, which would reverse the relation:
DataRelation relation = newDataRelation("ParentChild",
ds.Tables[0].Columns["ParentID"], //parentColumn
ds.Tables[0].Columns["ID"], //childColumn
true //createConstraints
);
So which is it? Why does his work? What's with the exception? Why can he create the constraint when he has nulls?
God it's hot in here.