2013-02-06 49 views
0

我从我的数据库返回一个值。数据类型是一个字符串。我检查了TypeName。不过,即使它打印了我正在检查的值,我的if条件仍然无效。有任何想法吗?经典的ASP记录集字段不被允许评估

while NOT prs.EOF 

    RecordStatus = prs("status") 


    If (RecordStatus = "S") Then 
     response.write("Scheduled!<br>") 
     prs.MoveNext 
    Else 
     response.write(RecordStatus & "<BR>") 
     prs.MoveNext 
    End If 

Wend 
prs.Close 
+1

Try Trim(RecordStatus)=“S” – Sunny

+0

你太棒了。非常感谢你。 –

+0

没问题。既然你已经收到了价值,我想这可能是原因。顺便说一下,我认为你是新手,因此我会将其作为回答发布,并将其标记为将其从未应答的队列中移除,从而为其他人节省时间。 – Sunny

回答

2

此外,请考虑将MoveNext放置到最后一行。

while NOT prs.EOF 

    RecordStatus = prs("status")  

    If (Trim(RecordStatus) = "S") Then 
     response.write("Scheduled!<br>") 
    Else 
     response.write(RecordStatus & "<BR>") 
    End If 

    prs.MoveNext  
Wend 
prs.Close 
+0

你说过,“试试Trim(RecordStatus)=”S“”。这也起作用。感谢您的建议,我也会尝试。 –

+0

修剪是解决方案,以上是代码重构。 – Sunny

0

同样的结果,代码半:

do while NOT prs.EOF 
    RecordStatus = ucase(trim(prs("status"))) 
    If RecordStatus = "S" Then response.write "Scheduled!<br>" Else response.write RecordStatus & "<br>" 
    prs.MoveNext 
loop 
prs.close 

你也可以做的SQL查询本身内部的情况下声明这个逻辑检查:

select case lower(status) when 's' then 'Scheduled!' else status end as sresult from <yourdatabase> 

然后使用代码:

do while NOT prs.EOF 
    sresult = prs("sresult") & "<br>" 
    response.write sresult 
    prs.MoveNext 
loop 
prs.close 

希望它hel p :)