how to add a relationship between tables in the dataset

北城余情 提交于 2019-12-25 03:55:55

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!