Error “The row doesn’t belong to the same DataSet as this relation.” when using DataRelation

If you get this error while trying to use DataRelation objects and calling GetChildRows on any given row it is most likely due to the fact that you have not added the DataRelation you created to the DataSet by calling the Add method of the DataSet like so:

C#
DataSet dt = new DataSet();
DataRelation dr = new DataRelation(“test”,dt.Tables[0].Columns[0],dt.Tables[1].Columns[1]);

//now this is probably what you forgot to do
dt.Relations.Add(dr);