问题
I have the following code to get the get the relationship between the tables in the same dataset , but when run the following code i encounter with error saying , these columns currently dont have unique values
DataResultSetDataSet dataset = resultSet as DataResultSetDataSet;
System.Data.DataSet menuDataSet = new System.Data.DataSet();
menuDataSet = dataset.Set;
menuDataSet.DataSetName = "Menus";
menuDataSet.Tables[0].TableName = "Menu";
DataRelation relation = new DataRelation("ParentChild", menuDataSet.Tables["Menu"].Columns["MenuID"], menuDataSet.Tables["Menu"].Columns["ParentID"], true);
relation.Nested = true;
menuDataSet.Relations.Add(relation);
menuXml= menuDataSet.GetXml();
}
回答1:
If your code isn't a typo (i.e., you're not trying to relate the table Menu to itself), check the values in the two columns (MenuID and ParentID). Without knowing exactly how your table(s) are set up, I would suspect that ParentID has repeated values, which is why you're getting the error you are.
来源:https://stackoverflow.com/questions/7005672/how-to-add-a-relationship-between-tables-in-the-dataset