troubleshooting Question

DataRelation - These columns currently don't have unique values

Avatar of deleyd
deleydFlag for United States of America asked on
2 Comments1 Solution16 ViewsLast Modified:
I have a database with tables like this:


Open in new window

XrefAB table:
ID   Name
--   ----
A    Alpha
B    Bravo
C    Charlie

Open in new window

Name    Data
----    ----
Alpha   1
Bravo   2
Charlie 3

Open in new window

I have a DataGridView displaying TableA.
And I have a TextBox to display Data from TableB.
+-----+         TextBox
|  A  |        +------+
|  B  |        |      |
|  C  |        +------+

Open in new window

User selects a line from DataGridView, and TextBox displays corresponding data.

For example, User selects line A. The XrefAB table says A maps to "Alpha". TableB name "Alpha" corresponds to data "1". Display "1" in TextBox.

This I can accomplish as follows: (I'm using an Oracle database. Assume 'connection' is a connection to the Oracle database.)
DataSet ds = new DataSet();
OracleDataAdapter adapterTableA = new OracleDataAdapter("Select * from TABLEA", connection);
OracleDataAdapter adapterXrefAB = new OracleDataAdapter("Select * from XREFAB", connection);
OracleDataAdapter adapterTableB = new OracleDataAdapter("Select * from TABLEB", connection);

adapterTableA.Fill(ds, "TableA");
adapterXrefAB.Fill(ds, "XrefAB");
adapterTableB.Fill(ds, "TableB");

DataRelation drA2Xref = new DataRelation("TableAXref", 

DataRelation drXref2B = new DataRelation("Xref2TableB", 

BindingSource xrefBS = new BindingSource();
BindingSource textBoxBS = new BindingSource();

xrefBS.DataSource = ds;
xrefBS.DataMember = "TableA";

textBoxBS.DataSource = xrefBS;
textBoxBS.DataMember = "Xref2TableB";

dataGridView.DataSource = ds;
dataGridView.DataMember = "TableA";

textBox.DataBindings.Add("Text", textBoxBS, "Data");

Open in new window

and this works OK.
Now I change the XrefAB table to:
ID   Name
--   ----
A    Alpha
B    Alpha
C    Charlie

Open in new window

Suppose user now selects from the DataGridView row B.
B maps to "Alpha".
"Alpha" maps to "1".
I'd like the TextBox to display a "1".

But it doesn't. Instead the whole thing blows up with the operating system complaining my XrefAB table Name column does not have unique values. The error message thrown is "These columns currently don't have unique values".

Why won't this work, and, how can I make this work?

David H.H.Lee
Digital Marketing (Hospitality)
Log in to continue reading
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform for $9.99/mo
View membership options
Unlock 1 Answer and 2 Comments.
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
The Value of Experts Exchange in My Daily IT Life

Experts Exchange (EE) has become my company's go-to resource to get answers. I've used EE to make decisions, solve problems and even save customers. OutagesIO has been a challenging project and... Keep reading >>


Owner of Outages.IO
Phoenix, Arizona, United States
Member Since 2016
Join a full scale community that combines the best parts of other tools into one platform.
Unlock 1 Answer and 2 Comments.
View membership options
“All of life is about relationships, and EE has made a virtual community a real community. It lifts everyone's boat.”
William Peck

Member since 2004