DataGridView绑定到两个表 [英] DataGridView binding to two tables
本文介绍了DataGridView绑定到两个表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的SQL查询
String sqlQuery =SELECT u.CallerName,t。* FROM users u INNER JOIN票t ON u.id = t.user WHERE u.CallerName ='tim.smith';
我正在使用WinForms
解决方案
如果您的查询结果是 DataTable ,那么您可以使用合并功能合并两个表。
DataTable table1 = GetTable1Data(...);
DataTable table2 = GetTable2Data(...);
table1.Merge(table2,true);
或者如果您的查询结果为列表,那么您可以使用与DataTable情况相同的方法,使用 AddRange 函数:
列表< YourClassType> list1 = GetList1Data(...);
列表< YourClassType> list2 = GetList2Data(...);
list1.AddRange(list2,true);
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
解决方案
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);
这篇关于DataGridView绑定到两个表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文