Note that there are some explanatory texts on larger screens.

plurals
  1. PODataRelation between two data tables - can't bind data to a listbox (C# .NET 3.5)
    text
    copied!<p>C# (.NET 3.5)</p> <p>I have an SQLite database with two tables - employees (the first column being id INTEGER PRIMARY KEY), and holidays (id INTEGER - meaning the ID of the employee; start DATE, end DATE - self-explanatory).</p> <p>My form contains textboxes, checkboxes etc. to represent the employee details - but say I'd also like a list box, listing all the holidays for the currently selected employee.</p> <p>So I need a data relation, as the list box is supposed to display only holidays one person at the time (IDs on both datatables needs to match).</p> <pre><code> var command = new SQLiteCommand("SELECT * FROM employees; SELECT * FROM holidays"); var connection=new SQLiteConnection(@"data source=C:\employees.db"); command.Connection = connection; SQLiteDataAdapter adapter = new SQLiteDataAdapter(command); DataSet d = new DataSet(); adapter.Fill(d); DataTable employees = d.Tables[0]; // [...] // here I'm databinding my textboxes etc. to various columns // of the employees data table - this works fine, navigation works well etc. // [...] DataTable holidays = d.Tables[1]; DataRelation relation; DataColumn master = employees.Columns[0]; DataColumn slave = holidays.Columns[0]; relation = new DataRelation("relation", master, slave); d.Relations.Add(relation); var dsView = holidays.DefaultView; listBox1.DisplayMember = "holidays.relation.start"; // &lt;= it wouldn't look good like that of course, but I just want to get the thing to work for now listBox1.DataSource = dsView; </code></pre> <ul> <li>but all I get is a listbox filled up with a bunch of "System.Data.DataRow" In this implementation, I tried to follow the tutorial I found on Akadia... Where do I go wrong? Thanks</li> </ul>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload