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