0
我使用vb.net 2012和msaccess2016作爲數據庫。我有4張桌子。項目主,關閉,購買,發行。現在我想在格式化的datagridview中得到一段時間的結果。以下是專欄。加入4條具有不同條件的表
- 項目名稱(項目主)
- 類別(項目主)
- 單位(項目主)
- 總數量(收盤)數量的
- 總和(採購)
- 總和的數量(發行)
我已經創建了一個查詢與物料主和關閉,它的工作。但是當我嘗試購買或發行時,沒有數據。購買和發行表沒有數據。
Dim sdate, edate As Date
sdate = dtsdate.Value
edate = dtedate.Value
Dim sqlSelect As String = "SELECT itemmaster.[Item Name], itemmaster.Category, itemmaster.Unit," _
& " Sum(Closing.Qty) AS Opening FROM itemmaster INNER JOIN Closing ON " _
& "itemmaster.[Item Name] = Closing.[Item Name] WHERE(((Closing.closeDate) >= #" & sdate & " # And (Closing.closeDate) <=#" & edate & " #))" _
& " GROUP BY itemmaster.[Item Name], itemmaster.Category, itemmaster.Unit"
Try
Dim con As New Odbc.OdbcConnection
con.ConnectionString = "Dsn=sdbinventory;"
Dim dt As New DataTable("user2")
Using cmd = New Odbc.OdbcCommand(sqlSelect, con)
con.Open()
Dim da As New System.Data.Odbc.OdbcDataAdapter(sqlSelect, con)
da.Fill(dt)
con.Close()
End Using
dgtvreport.DataSource = dt
Catch ex As Exception
Throw
End Try
你能幫我添加其餘兩欄。 感謝
我查詢
PARAMETERS sdate DateTime, edate DateTime;
SELECT itemmaster.[Item Name], itemmaster.Category, itemmaster.Unit, Sum(Closing.Qty) AS SumOfQty1, Sum(Purchase.Qty) AS SumOfQty, Sum(Issue.Quantity) AS SumOfQuantity
FROM ((itemmaster INNER JOIN Closing ON itemmaster.[Item Name] = Closing.[Item Name]) INNER JOIN Issue ON itemmaster.[Item Name] = Issue.[Item Name]) INNER JOIN Purchase ON itemmaster.[Item Name] = Purchase.[Item Name]
WHERE (((Closing.closeDate)>=[sdate] And (Closing.closeDate)<=[edate]) AND ((Purchase.PDate)>=[sdate] And (Purchase.PDate)<=[edate]) AND ((Issue.Idate)>=[sdate] And (Issue.Idate)<=[edate]))
GROUP BY itemmaster.[Item Name], itemmaster.Category, itemmaster.Unit;
我試圖在訪問運行它。還添加了示例數據。我只想從itemmaster導入所有項目名稱,類別和單位。現在我想添加下一列的開盤股票併購買和發行。我想創建並逐項報告。
像
Item Name Category Unit Opening Purchased Issued Balance
item1 Grocery Kg 2 3 4 1
item2 beverages PCS 0 1 1 0
Item3 vegetables kg 2 0 0 2
item4 consumable Pkt 10 2 1 11
您是否驗證過這兩個表中實際上是否有匹配的數據? –
是的,所有人都有一個共同的字段作爲項目名稱。但購買和發行表沒有數據。 – Deb
如果這些表沒有數據,爲什麼您希望查詢返回任何內容? –