当我尝试使用ASP.NET在Visual Studio中调试此代码时出现此错误。我有一个Room
和一个Booking
表,它们都填充了数据。我们的想法是让语句从表单(vb变量arriveDate
和departDate
)和房间大小(vb变量bedno
)中获取用户定义的日期,并返回所有匹配的房间用户选择的房间大小以及在用户选择的日期之间未预订的退房。
为了测试目的,我已经暂时给出了变量值。然后,我使用结果填充表单页面上的网格。
代码如下:
Dim bedno As Integer = 3
Dim arriveDate As Date = Date.FromOADate(12 / 8 / 2017)
Dim departDate As Date = Date.FromOADate(17 / 8 / 2017)
Using con As New SqlConnection(constr)
Using cmd As New SqlCommand("SELECT RoomTable.RoomNumber, RoomTable.RoomBeds, RoomTable.RoomPricePerNight, BookingTable.RoomNumber, BookingTable.ArriveDate, BookingTable.DepartDate FROM RoomTable LEFT JOIN BookingTable ON ROoomTable.RoomNumber=BookingTable.RoomNumber WHERE(BookingRoomTable.RoomBeds = " & bedno & ") AND (" & arriveDate & "NOT BETWEEN BookingTable.ArriveDate AND BookingTable.DepartDate) AND (" & departDate & "NOT BETWEEN BookingTable.ArriveDate AND BookingTable.DepartDate)")
Using sda As New SqlDataAdapter()
cmd.Connection = con
sda.SelectCommand = cmd
Using dt As New DataTable()
sda.Fill(dt)
GridView1.DataSource = dt
GridView1.DataBind()
End Using
End Using
End Using
End Using
End Sub
所有出现的错误都是
'附近的语法不正确:'"
我无法弄清楚问题所在。非常感谢任何帮助,谢谢。