ndfweb.cn

ASP判斷數據庫空值


2008-12-29 10:35:16 (6628)




由於各種字段屬性不同,判斷字段是否為空的方法也各異.
下麵是一個通用函數,免去了還要看字段類型之苦.
以下是代碼片段:

'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

本文版权:http://www.ndfweb.cn/news-161.html
  NDF俱乐部
  国际域名注册
  建站咨询
简体中文 NDF网站建设淘宝店 | ICO图标在线生成 | 外贸网站建设 | 联系我们
©2007-2025 NDF Corporation 鲁ICP备08005967号 Sitemap - RSSRSS订阅