需要一些幫助,我遇到的問題。 這是代碼:問題與選擇哪裏不是/存在子查詢(VB.NET,訪問)
Private Sub dtpStartDate_ValueChanged(sender As Object, e As EventArgs) Handles dtpStartDate.ValueChanged
startDateChanged = 1
If endDateChanged = 1 Then
cbLocation.Enabled = True
cbLocation.Items.Clear()
cbLocation.Items.Add(New ListViewItem(""))
Dim unbookedLocationsSQL As String = "SELECT locationID FROM Locations WHERE NOT EXISTS (Select LocationID FROM Bookings WHERE @startDate <= bookingEndDate AND bookingStartDate <= @endDate)"
Dim unbookedLocationsCommand = New OleDbCommand(unbookedLocationsSQL, globalVariables.objConnection)
Dim unbookedLocationsAdapter As New OleDbDataAdapter(unbookedLocationsSQL, globalVariables.objConnection)
Dim unbookedLocationsDataSet As New DataSet
unbookedLocationsCommand.Parameters.AddWithValue("startDate", dtpStartDate.Value)
unbookedLocationsCommand.Parameters.AddWithValue("endDate", dtpEndDate.Value)
unbookedLocationsAdapter.Fill(unbookedLocationsDataSet, "Locations")
With cbLocation
.DataSource = unbookedLocationsDataSet.Tables("Locations")
.DisplayMember = "locationID"
.ValueMember = "locationID"
End With
End If
End Sub
首先第一件事情,如果你改變了SQL語句「SELECT * FROM位置」組合框中顯示的只是所有的位置。
我想要達到的是這個;當某人更改了兩個日期時間選擇器時,將啓用組合框並填充未在這兩個日期之間預訂的位置列表(由預訂表確定)。 我知道SQL語句是錯誤的。我嘗試過各種各樣的組合,並嘗試隔離點和片斷,但我無法獲得任何子查詢來執行我想要的操作。
任何幫助,將不勝感激。
你嘗試過隔離此查詢? 'Select LocationID FROM Bookings WHERE @startDate <= bookingEndDate AND bookingStartDate <= @endDate)「' – Codemunkeee 2014-11-21 03:06:40