Cheat for “These columns don’t currently have unique values” error

Ordinary when you create a parent-child relationship between DataTables in a DataSet – there is a requirement that all values of the parent columns need to be unique. If they’re not – you will get an error: “These columns don’t currently have unique values“.

But there’re times when you need to make the relationship work even if those values are not unique. The solution is not to create constrain when creating the relationship. This can be done for example by passing FALSE as value for createConstrains parameter of Dataset.Relations.Add method:

oMyDataSet.Relations.Add("MyRel", _
oMyDataSet.Tables("TheParent").Columns("ParentColumn"), _
dtSet.Tables("TheChild").Columns("ChildColumn"), _
False)

14 replies on “Cheat for “These columns don’t currently have unique values” error”

  1. I say thank you for you because you had shared this solutions.
    ๐Ÿ™‚

  2. i need avoid datagridview duplicate row pls give some suggestion for that

  3. @ravi I suggest eliminate duplicates at the source before you bind data to the grid. E.g. if you’re running a SELECT statement – do a SELECT DISINCT – this is oversimplification, but that’s the idea – eliminate duplicates before they hit the grid.

Leave a Reply

Your email address will not be published. Required fields are marked *