code_junkie

ADO.NET: Adding DataRelation to a DataSet; which is parent and which is child?

Nov 12th, 2011
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. ID ParentID Text
  2. === ========= =============
  3. 1 (null) Product
  4. 2 (null) Applications
  5. 3 1 Background
  6. 4 1 Details
  7. 5 2 Mobile
  8.  
  9. public DataRelation(
  10. string relationName,
  11. DataColumn parentColumn,
  12. DataColumn childColumn,
  13. bool createConstraints
  14. )
  15.  
  16. DataRelation relation = newDataRelation("ParentChild",
  17. ds.Tables[0].Columns["ID"], //parentColumn
  18. ds.Tables[0].Columns["ParentID"] //childColumn,
  19. true //createConstraints
  20. );
  21.  
  22. This constraint cannot be enabled
  23. as not all values have corresponding parent values.
  24.  
  25. DataRelation relation = newDataRelation("ParentChild",
  26. ds.Tables[0].Columns["ParentID"], //parentColumn
  27. ds.Tables[0].Columns["ID"], //childColumn
  28. true //createConstraints
  29. );
  30.  
  31. relation.Nested = true;
  32. ds.Relations.Add(relation);
Add Comment
Please, Sign In to add comment