Cocoa Dev
Cocoa Dev

Reputation: 9561

DataGridView binding to two tables

I have two tables. Most of the data is coming from the first table but there is a second table which has a column which I want to present in my UI

Here is my SQL Query

String sqlQuery = "SELECT u.CallerName, t.* FROM users u INNER JOIN tickets t ON u.id = t.user WHERE u.CallerName = 'tim.smith'";

I am using WinForms

Upvotes: 0

Views: 5160

Answers (2)

Vano Maisuradze
Vano Maisuradze

Reputation: 5909

If your query result is DataTable, then you can use Merge function to merge two table.

DataTable table1 = GetTable1Data(...);
DataTable table2 = GetTable2Data(...);

table1.Merge(table2, true);

Or if your query result is List, then you can use same approach as in DataTable case, using AddRange function:

List<YourClassType> list1 = GetList1Data(...);
List<YourClassType> list2 = GetList2Data(...);

list1.AddRange(list2, true);

Upvotes: 1

Sam Sussman
Sam Sussman

Reputation: 1045

It looks like you are doing just fine. When binding with the DataGridView you can use: Eval("CallerName") to access the other column, but that column should work like all of the others.

Upvotes: 0

Related Questions