开发者

CommandText is not initialized

I have this code

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", "%"))

And the error CommandText has not been initialized keeps showing up on the IIS event viewer log

I can't replicate the problem myself but I know it is happening can anyone suggest anything

The error says it happens with this line dd1.DataSource = LogData.StermQ3(datelistquery).Tables(0).DefaultView

Thanks

Jamie


I think you are in a situation where none of the following conditions are met:

Session("TenHolStDateHP1") = "%"
Session("TenHolStDateHP1") = ""
Session("holidayduration") = "3/4" 
Session("holidayduration") = "14"
Session("holidayduration") = "7" 

Since you don't initialize datelistquery to anything and you end in an else if it seems possible that you are not assigning a query to this string and could pass an empty string to your StermQ3 function.

You may want to add an else statement to the end of your chain of if/else if statements as a catchall. What you would set datelistquery to in the else statement depends on what you are doing.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜