如何连接两个表并在一个列表视图中显示它们? [英] How to join two tables and show them in one listview?
本文介绍了如何连接两个表并在一个列表视图中显示它们?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用列表视图,它有两个不同的数据库表格。这是我正在尝试的代码:
I am using list-view that has it column form two different db tables .Here is my code that i am trying :
try
{
String Query = "select id,Code,Description,Rate,Bottles,Supply,Empty,Amount,Received,
Customer_New.Opening_Date,Customer_New.Clients_Title,Customer_New.Cust_Id
from (Items INNER JOIN Customer_New on Customer_New.Cust_Id=Items.Cust_Id)
,Customer_New";
SQLiteDataAdapter dba = new SQLiteDataAdapter(Query, GlobalVars.conn);
DataSet testDs = new DataSet();
dba.Fill(testDs, "Items"); //error
dba.Fill(testDs, "Customer_New"); //error
DataTable dt = testDs.Tables[0];
this.lvcmodify.DataContext = testDs.Tables[0].DefaultView;
lvcmodify.ItemsSource = dt.DefaultView;
testDs.Dispose();
dba.Dispose();
dt.Dispose();
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
有谁知道如何在列表视图中完成此功能? 。请帮我纠正这段代码。谢谢
Does anyone knows how i can accomplish this functionality in list view ? .Please help me to correct this code.Thanks
推荐答案
请先阅读我的评论。
没有2张桌子!只有2个源表和一个目标表,因为您使用INNER JOIN
语句加入它们。
Please, read my comments first.
There aren't 2 tables! There are 2 source tables and one destination table only, because you joined them withINNER JOIN
statement.
SELECT it.id, it.Code, it.Description, it.Rate, it.Bottles, it.Supply,
it.Empty, it.Amount, it.Received, cn.Opening_Date, cn.Clients_Title, cn.Cust_Id
FROM Items AS it INNER JOIN Customer_New AS cn on it.Cust_Id=cn.Cust_Id
这篇关于如何连接两个表并在一个列表视图中显示它们?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文