我正在尝试在 vb.net 中执行此选择查询,但它向我抛出了 No Value Given For One or More Required Parameters 错误。我一直在重新检查我的代码,但看不出有什么问题。
SELECT
使用表格提取 houseno、housename、street、productname、sequenceno 和数量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)`
在此之后,使用数据适配器调用命令以填充数据集中的表。
'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。