首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Response.Write to a String - ASP Classic

Response.Write to a String - ASP Classic
EN

Stack Overflow用户
提问于 2014-12-27 02:59:04
回答 2查看 675关注 0票数 1

我有一个SQL查询,它使用Do Until循环从数据库中检索值。循环内的SQLCondition值显示正确,但如果我想在循环外显示该值,它不起作用:

代码语言:javascript
复制
If rReseller > 0 Then
    sql2 = "SELECT rl.countryid FROM reseller_locator rl WHERE rl.resellerid = " & rReseller & " AND rl.countryid <> '" & iCountryID & "'"

    'response.write sql2
    Set rsResellerLocator=Conn.Execute(sql2)

    If not rsResellerLocator.EOF Then 

        do until rsResellerLocator.eof  

            iRCountryID = rsResellerLocator("countryid")
            SQLCondition = iRCountryID & ", "

            response.write SQLCondition

        rsResellerLocator.movenext
        loop    

    Else
        SQLCondition = ""
    End If  
        response.write SQLCondition
End If

循环内部的response.write显示为"2,3,4,5“。但是来自循环外部的response.write显示为"5“。

如何将循环内部值存储到要在查询外部使用的字符串中?

EN

回答 2

Stack Overflow用户

发布于 2014-12-27 03:06:27

您确定内循环工作正常吗?我不明白为什么它会显示"2,3,4,5“--就像你现在的代码一样,它总是只显示一个数字。试试这个:

替换

代码语言:javascript
复制
SQLCondition = iRCountryID & ", "

使用

代码语言:javascript
复制
SQLCondition = SQLCondition  & ", " & iRCountryID

这将保存条件字符串,否则只保存最新的条件

票数 0
EN

Stack Overflow用户

发布于 2018-08-17 20:43:45

使用此选项将所需数据保存为字符串

代码语言:javascript
复制
If rReseller > 0 Then
    sql2 = "SELECT rl.countryid FROM reseller_locator rl WHERE rl.resellerid = " & rReseller & " AND rl.countryid <> '" & iCountryID & "'"

    'response.write sql2
    Set rsResellerLocator=Conn.Execute(sql2)

    If not rsResellerLocator.EOF Then 

        do until rsResellerLocator.eof  

            iRCountryID = rsResellerLocator("countryid")
            SQLCondition = iRCountryID & ", "
    
     SQLConditionAll=""&SQLConditionAll&""&SQLCondition&""
    
            response.write SQLCondition

        rsResellerLocator.movenext
        loop    

    Else
        SQLCondition = ""
    End If  
        response.write SQLCondition
End If

现在,您可以使用Response.write SQLConditionAll在字符串中显示所需数据

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/27660850

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档