0
我們向用戶展示搜索特定日期的記錄或按日期範圍搜索的選項。如果選擇日期不可用,則顯示未來30天的結果?
但是,如果用戶選擇的日期不可用,而不是顯示未找到用戶選擇的消息,則會顯示接下來30天的記錄。
到目前爲止,我的查詢顯示的日期比今天早。
這是錯誤的。
任何想法下面的代碼有什麼問題?
If ViewSelect = "Range" Then
sb.Append(If(startedWhere, andors, " WHERE "))
sb.Append("(CONVERT(VARCHAR(10), facilityAvailabilityDate, 101) >= @FromDate And CONVERT(VARCHAR(10), facilityAvailabilityDate, 101) <= @EndDate)")
cmd.Parameters.AddWithValue("@FromDate", txtFromDate.Text)
cmd.Parameters.AddWithValue("@EndDate", txtToDate.Text)
startedWhere = True
ElseIf ViewSelect = "Specific" Then
sb.Append(If(startedWhere, andors, " WHERE "))
sb.Append("(CONVERT(VARCHAR(10), facilityAvailabilityDate, 101) = @SpecificDate)")
cmd.Parameters.AddWithValue("@SpecificDate", txtSpecificDate.Text)
startedWhere = True
End If
cmd.CommandText = sb.ToString()
'Response.Write(sb)
'Response.End()
' Dim cmd As New SqlCommand(strQuery)
Dim dt As DataTable = GetData(cmd)
'No records found, so display records for next 30 days.
If dt.Rows.Count = 0 Then
cmd.Parameters.Clear()
cmd.Parameters.AddWithValue("@FromDate", Date.Today.AddMonths(-1))
cmd.Parameters.AddWithValue("@EndDate", Date.Today.ToString("MM/dd/yyyy"))
cmd.CommandText = "Select siteID,siteName,bldgName,Capacity,AvailableFacilities,facilityAvailabilityDate,Status " & _
",amenities,[Rental Fees] RentalFees,[Extra Hour Fees] ExtraHourFees,[Deposit Fees] DepositFees,[Cancellation Fees] CancelFees,[Key Deposit Fees] KeyDepFees, Duration " & _
" FROM ParksNRecsData" & _
" where facilityAvailabilityDate Between @FromDate And @EndDate"
dt = GetData(cmd)
End If
GridView1.DataSource = dt
GridView1.DataBind()
SQL Server是選擇的數據庫。
在此先感謝
您的代碼似乎是選擇前30天的記錄,而不是接下來的30天。你不需要FromDate等於今天的日期,EndDate是date.AddMonths(1)? – Alan 2014-12-01 16:15:37