ID
--
A
B
C
XrefAB table:ID Name
-- ----
A Alpha
B Bravo
C Charlie
TableB:Name Data
---- ----
Alpha 1
Bravo 2
Charlie 3
I have a DataGridView displaying TableA.DataGridView
+-----+ TextBox
| A | +------+
| B | | |
| C | +------+
+-----+
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",
ds.Tables["TableA"].Columns["ID"],
ds.Tables["XrefAB"].Columns["ID"]);
ds.Relations.Add(drA2Xref);
DataRelation drXref2B = new DataRelation("Xref2TableB",
ds.Tables["XrefAB"].Columns["Name"],
ds.Tables["TableB"].Columns["Data"]);
ds.Relations.Add(drXref2B);
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");
and this works OK.ID Name
-- ----
A Alpha
B Alpha
C Charlie
Suppose user now selects from the DataGridView row B.C# is an object-oriented programming language created in conjunction with Microsoft’s .NET framework. Compilation is usually done into the Microsoft Intermediate Language (MSIL), which is then JIT-compiled to native code (and cached) during execution in the Common Language Runtime (CLR).
TRUSTED BY
ASKER
Open in new window
The SQL gives a resulting table of:Open in new window
We then define relation between TableA.ID and this table ID.Now as user browses TableA in a DataGridView, the text box fills with corresponding value in DATA column of this table.