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

来源:百度知道 编辑:UC知道 时间:2024/05/08 04:42:01
数据库中存有图片地址
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">

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

<%
if isnull(rs("imgurl")) or rs("imgurl")="" then
imgurl="img/wen.gif"
else
imgurl=(rs("imgurl")
end if
%>

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