我有这段代码
Dim LogData As sterm.markdata = New sterm.markdata()
Dim datelistquery As String
Dim properdate As String
If Session("TenHolStDateHP1") = "%" or Session("TenHolStDateHP1") = "" Then
If Session("passedPropId") = "" Then
'QUERY USED IF NO DATE SELECTED AND A PROPID HAS NOT BEEN PASSED
datelistquery = "SELECT DISTINCT property_id, ' - Sleeps ' + cast(number_slept as varchar) as combsleeps, number_slept FROM openquery ("+Application("hpbDsrc")+",'SELECT property_id, number_slept FROM web_details WHERE location = ''"&Session("TenChosenLocCode")&"'' AND pets_yn like ''"&Session("TenPets")&"'' AND number_slept >= ''"&Session("TenAdults")&"'' AND on_hold = ''NO'' AND booked = ''NO'' ') ORDER BY number_slept, property_id"
Else
'QUERY USED IF NO DATE SELECTED AND A PROPID HAS BEEN PASSED
datelistquery = "SELECT DISTINCT property_id, ' - Sleeps ' + cast(number_slept as varchar) as combsleeps, number_slept FROM openquery ("+Application("hpbDsrc")+",'SELECT property_id, number_slept FROM web_details WHERE location = ''"&Session("TenChosenLocCode")&"'' AND property_id = ''"&Session("passedPropId")&"'' AND pets_yn like ''"&Session("TenPets")&"'' AND number_slept >= ''"&Session("TenAdults")&"'' AND on_hold = ''NO'' AND booked = ''NO'' ') ORDER BY number_slept, property_id"
End If
Else
If Session("holidayduration") = "7" Then
If Session("passedPropId") = "" Then
'QUERY USED IF DATE SELECTED AND 7 NIGHTS AND A PROPID HAS NOT BEEN PASSED
datelistquery = "SELECT DISTINCT property_id, ' - Sleeps ' + cast(number_slept as varchar) as combsleeps, number_slept FROM openquery ("+Application("hpbDsrc")+",'SELECT property_id, number_slept FROM web_details WHERE part_full_flag = ''F'' AND location = ''"&Session("TenChosenLocCode")&"'' AND pets_yn like ''"&Session("TenPets")&"'' AND number_slept >= ''"&Session("TenAdults")&"'' AND year_week = ''"&Session("TenHolStDateHP1")&"'' AND on_hold = ''NO'' AND booked = ''NO'' ') ORDER BY number_slept, property_id"
Else
'QUERY USED IF DATE SELECTED AND 7 NIGHTS AND A PROPID HAS BEEN PASSED
datelistquery = "SELECT DISTINCT property_id, ' - Sleeps ' + cast(number_slept as varchar) as combsleeps, number_slept FROM openquery ("+Application("hpbDsrc")+",'SELECT property_id, number_slept FROM web_details WHERE part_full_flag = ''F'' AND location = ''"&Session("TenChosenLocCode")&"'' AND property_id = ''"&Session("passedPropId")&"'' AND pets_yn like ''"&Session("TenPets")&"'' AND number_slept >= ''"&Session("TenAdults")&"'' AND year_week = ''"&Session("TenHolStDateHP1")&"'' AND on_hold = ''NO'' AND booked = ''NO'' ') ORDER BY number_slept, property_id"
End If
Else If Session("holidayduration") = "14" Then
theyear = Left(Session("TenHolStDateHP1"), 4)
theweek = Right(Session("TenHolStDateHP1"), 2)
If theweek < "52" then
theyear = theyear
If theweek < "10" then
theweek = "0" & theweek + 1
Else
theweek = theweek + 1
End If
Else
If (theyear = "2015" and theweek < "53") or (theyear = "2020" and theweek < "53") or (theyear = "2026" and theweek < "53") or (theyear = "2032" and theweek < "53") or (theyear = "2037" and theweek < "53") then
theyear = theyear
theweek = "53"
Else
theyear = theyear + 1
theweek = "01"
End If
End If
If Session("passedPropId") = "" Then
'QUERY USED IF DATE SELECTED AND 14 NIGHTS AND A PROPID HAS NOT BEEN PASSED
datelistquery = "SELECT DISTINCT property_id, ' - Sleeps ' + cast(number_slept as varchar) as combsleeps, number_slept FROM openquery ("+Application("hpbDsrc")+",'SELECT property_id, number_slept FROM web_details WHERE part_full_flag = ''F'' AND location = ''"&Session("TenChosenLocCode")&"'' AND pets_yn like ''"&Session("TenPets")&"'' AND number_slept >= ''"&Session("TenAdults")&"'' AND year_week in (''"&Session("TenHolStDateHP1")&"'',''"& theyear & theweek &"'') AND on_hold = ''NO'' AND booked = ''NO'' GROUP BY property_id HAVING count(property_id) > 1 ') ORDER BY number_slept, property_id"
Else
'QUERY USED IF DATE SELECTED AND 14 NIGHTS AND A PROPID HAS BEEN PASSED
datelistquery = "SELECT DISTINCT property_id, ' - Sleeps ' + cast(number_slept as varchar) as combsleeps, number_slept FROM openquery ("+Application("hpbDsrc")+",'SELECT property_id, number_slept FROM web_details WHERE part_full_flag = ''F'' AND location = ''"&Session("TenChosenLocCode")&"'' AND property_id = ''"&Session("passedPropId")&"'' AND pets_yn like ''"&Session("TenPets")&"'' AND number_slept >= ''"&Session("TenAdults")&"'' AND year_week in (''"&Session("TenHolStDateHP1")&"'',''"& theyear & theweek &"'') AND on_hold = ''NO'' AND booked = ''NO'' GROUP BY property_id HAVING count(property_id) > 1 ') ORDER BY number_slept, property_id"
End If
Else If Session("holidayduration") = "3/4" Then
If Session("passedPropId") = "" Then
'QUERY USED IF DATE SELECTED AND 3/4 NIGHTS AND A PROPID HAS NOT BEEN PASSED
datelistquery = "SELECT DISTINCT property_id, ' - Sleeps ' + cast(number_slept as varchar) as combsleeps, number_slept FROM openquery ("+Application("hpbDsrc")+",'SELECT property_id, number_slept FROM web_details WHERE (part_full_flag = ''P'' or split_weeks = ''Y'') AND location = ''"&Session("TenChosenLocCode")&"'' AND pets_yn like ''"&Session("TenPets")&"'' AND number_slept >= ''"&Session("TenAdults")&"'' AND year_week = ''"&Session("TenHolStDateHP1")&"'' AND on_hold = ''NO'' AND booked = ''NO'' ') ORDER BY number_slept, property_id"
Else
'QUERY USED IF DATE SELECTED AND 3/4 NIGHTS AND A PROPID HAS BEEN PASSED
datelistquery = "SELECT DISTINCT property_id, ' - Sleeps ' + cast(number_slept as varchar) as combsleeps, number_slept FROM openquery ("+Application("hpbDsrc")+",'SELECT property_id, number_slept FROM web_details WHERE (part_full_flag = ''P'' or split_weeks = ''Y'') AND location = ''"&Session("TenChosenLocCode")&"'' AND property_id = ''"&Session("passedPropId")&"'' AND pets_yn like ''"&Session("TenPets")&"'' AND number_slept >= ''"&Session("TenAdults")&"'' AND year_week = ''"&Session("TenHolStDateHP1")&"'' AND on_hold = ''NO'' AND booked = ''NO'' ') ORDER BY number_slept, property_id"
End If
End If
'Query to get date in nice format
properdate = "SELECT * FROM openquery ("+Application("hpbDsrc")+", 'SELECT starting_period from web_header WHERE year_week = ''"&Session("TenHolStDateHP1")&"'' ')"
Dim drCode7 As DataSet = LogData.StermQ3(properdate)
dgAvailable2.DataSource = drCode7.Tables(0).DefaultView
dgAvailable2.DataBind()
End If
dd1.DataSource = LogData.StermQ3(datelistquery).Tables(0).DefaultView
dd1.DataBind()
dd1.Items.Insert(0, new listitem("Any location", "%"))
并且尚未初始化错误CommandText会一直显示在IIS事件查看器日志
上我不能自己复制这个问题,但我知道这种情况正在发生,任何人都可以提出任何建议
错误表明这行dd1.DataSource = LogData.StermQ3(datelistquery).Tables(0).DefaultView
由于
杰米
答案 0 :(得分:0)
我认为您处于以下任何条件都不符合的情况:
Session("TenHolStDateHP1") = "%"
Session("TenHolStDateHP1") = ""
Session("holidayduration") = "3/4"
Session("holidayduration") = "14"
Session("holidayduration") = "7"
由于您没有将datelistquery
初始化为任何内容并且以else if
结尾,因此您可能无法为此字符串分配查询,并且可能会将空字符串传递给您的{{1}功能。
您可能希望在StermQ3
语句链的末尾添加else
语句作为捕获。你在else语句中设置if/else if
的内容取决于你正在做什么。