0

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();
        }
mahesh
  • 3,067
  • 16
  • 69
  • 127
  • Are you trying to join the table to itself? – Roman Aug 10 '11 at 03:55
  • ya i am establishing parent child relationship , based on the items contained in the dataset – mahesh Aug 10 '11 at 03:57
  • I mean it looks like you're joining table `Menu` to table `Menu`. Is that a typo, or is that what you really intended to do? – Roman Aug 10 '11 at 04:00
  • Thanks for the reply , the problem i was facing was my datset contained duplicate values now i got resolved. – mahesh Aug 10 '11 at 04:29

1 Answers1

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.

Tim
  • 28,212
  • 8
  • 63
  • 76