我試圖在vb.net中執行此選擇查詢,但它引發了給定值爲一個或多個必需參數的錯誤。我不斷重新檢查我的代碼,但看不到有什麼問題。沒有賦予一個或多個必需參數的值,使用子選擇查詢
SELECT
語句中使用DailyDelivery
表,其中roundID = selectedID
Command.CommandText =
"SELECT customerid,
productid,
quantity,
(SELECT houseno
FROM customer
WHERE customer.customerid = dailydelivery.customerid) AS HouseNo,
(SELECT housename
FROM customer
WHERE customer.customerid = dailydelivery.customerid) AS HouseName,
(SELECT street
FROM customer
WHERE customer.customerid = dailydelivery.customerid) AS Street,
(SELECT sequenceno
FROM customer
WHERE customer.customerid = dailydelivery.customerid) AS SequenceNo,
(SELECT roundid
FROM customer
WHERE customer.customerid = dailydelivery.customerid) AS RoundID,
(SELECT productname
FROM product
WHERE product.productid = dailydelivery.productid) AS ProductName
FROM dailydelivery
WHERE issuedate = @TodaysDate
AND roundid = @SelectedID
ORDER BY sequenceno,
street,
houseno,
housename"
'Add parameter for command (TodaysDate being today's date)
`Command.Parameters.AddWithValue("@TodaysDate", Today.Date)`
'Add parameter for command (SelectedID being the current roundID)
`Command.Parameters.AddWithValue("@SelectedID", SelectedID)`
在此之後,命令使用數據適配器來填充表叫拉的HouseNo,housename,街道,產品名稱,sequenceno和數量在數據集中。
'Open connection to the database
dbConnection.Open()
'Set command's connection as dbconnection
Command.Connection = dbConnection
'Set the data adapter's select command as command
DataAdpt.SelectCommand = Command
'Fill ActualDelivery table in selectedDataset with the results of query, using the data adapter
DataAdpt.Fill(SelectedDataset, "ActualDelivery")
'Close connection to the database
dbConnection.Close()
錯誤發生在DataAdapt.Fill
行。我正在使用VB Express 2008和Access 2013.
我覺得很難相信Access 2013的SQL不支持'JOIN' - 哦,[它](http://msdn.microsoft.com/en-us/library/office/ff197346。 aspx) - 你可以在其他任何事情之前大大簡化這個查詢。 – 2013-04-05 14:22:53
什麼類型的命令對象是'Command'?你能爲此展示宣言/作業嗎? – 2013-04-05 14:29:17
'Command'在模塊中使用'Public Command As New OleDb.OleDbCommand'進行聲明 – Jamie 2013-04-05 14:32:58