asp判断数据库中读取的是否为空值

数据库中存有图片地址
imgurl vachar类型的 ,上传了图片就是图片地址,不上传就为空

前台读的时候我想判断是否为空,为空的话,给个默认值
我是这样写的,但好象不对
<%
if rsall("imgurl")="" then
imgurl="img/wen.gif"
else
imgurl=rsall("imgurl")
end if
%>
<img src="upload/pdt/<%=rsall("imgurl")%>" width="70" height="55">

请问应该怎么判断???????

第1个回答  2007-11-01
asp 没有判断是否为空的函数,你需要自己做一个函数,下面的可以验证是否为空:
'Check a variable isn't "empty"
Function IsBlank(ByRef TempVar)
'by default, assume it's not blank
IsBlank = False
'now check by variable type
Select Case VarType(TempVar)
'Empty & Null
Case 0, 1
IsBlank = True
'String
Case 8
If Len(TempVar) = 0 Then
IsBlank = True
End If
'Object
Case 9
tmpType = TypeName(TempVar)
If (tmpType = "Nothing") Or (tmpType = "Empty") Then
IsBlank = True
End If
'Array
Case 8192, 8204, 8209
'does it have at least one element?
If UBound(TempVar) = -1 Then
IsBlank = True
End If
End Select
End Function

应用实例:

If IsBlank(rs("upic")) Then
upicurl="/images/nonepic.jpg"
Else
upicurl=rs("upic")
End If
第2个回答  2007-10-31
应该这样:
<%
if isnull(rs("imgurl")) or rs("imgurl")="" then
imgurl="img/wen.gif"
else
imgurl=(rs("imgurl")
end if
%>

第一 isnull(rs("name"))跟rs("name")=""是全不同的
第二 当rs("name")从未被付值时它就是一个无效的变量或是一个空变量及 isnull(rs("name"))=true
第三 当rs("name")=""时其实它已经是一个有效的变量了只不过是一个空字串而已及 isnull(rs("name"))=false
第四 if isnull(rs("name")) or rs("name")="" then
其实是为获得 rs("name") 是否是有效变量或者它是不是一个空字串
第五 当只判断rs("name")=""时将会把无效变量当成非空字串
第六 当只判断isnull(rs("name"))时将无法获得是否真的是空字串
第3个回答  2007-11-04
<%
if isnull(rs("imgurl")) or rs("imgurl")="" then
imgurl="img/wen.gif"
else
imgurl=(rs("imgurl")
end if
%>本回答被提问者采纳

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网