1
另一個問題。用這個SQL的東西掙扎一點。如何在Jet SQL中的DataSet中合併兩個DataTable?
我在ADO.NET中生成2個查詢表。我想從這兩個表中執行第三個查詢 - 連接數據庫中不存在,但存在於數據集中。我不能爲我的生活找出如何做到這一點。我不想連接到數據庫,但要連接到數據集
我看着嘗試DataReaders,TableAdapters,DataTable.Select(它只適用於一個表)和其他東西。答案在於LINQ for Datasets?
感謝 安迪
Dim strSelect As String
Dim dsmcmd As OleDbDataAdapter
Dim dsm as New DataSet
strSelect = "TRANSFORM Sum(Items.amount) AS total SELECT Accounts.accCategory, Accounts.ID, Accounts.comment AS Account FROM Accounts INNER JOIN Items ON Accounts.ID = Items.accFrom WHERE (((Year([idate]))=2013) AND ((Items.category)<>3 Or (Items.category) Is Null) AND ((Accounts.accCategory)=6 OR (Accounts.accCategory)=7) AND ((Accounts.curr)=1)) GROUP BY Accounts.accCategory, Accounts.ID, Accounts.comment PIVOT Format(idate,'mmm') IN ('Jan','Feb','Mar','Apr', 'May','Jun','Jul','Aug','Sep','Oct','Nov','Dec')"
dsmcmd = New OleDbDataAdapter(strSelect, cn)
dsmcmd.Fill(dsm, "Spent")
strSelect = "TRANSFORM Sum(Items.amount) AS total SELECT Accounts.accCategory, Accounts.ID, Accounts.comment AS Account FROM Accounts INNER JOIN Items ON Accounts.ID = Items.accFrom WHERE (((Year([idate]))=2013) AND ((Items.category)=3) AND ((Accounts.accCategory)=6) AND ((Accounts.curr)=1)) GROUP BY Accounts.accCategory, Accounts.ID, Accounts.comment PIVOT Format(idate,'mmm') IN ('Jan','Feb','Mar','Apr', 'May','Jun','Jul','Aug','Sep','Oct','Nov','Dec')"
dsmcmd = New OleDbDataAdapter(strSelect, cn)
dsmcmd.Fill(dsm, "Allocated")
strSelect = "SELECT Totals.accCategory, Totals.ID, Totals.Account, Sum(Totals.Jan) AS Jan FROM (SELECT * FROM Allocated UNION SELECT * FROM Spent) AS Totals GROUP BY Totals.accCategory, Totals.ID, Totals.Account"
dsmcmd = New OleDbDataAdapter(strSelect, <** WHAT DO I PUT HERE **>)
dsmcmd.Fill(dsm, "Balance")