asp提示無效使用?Null:?Replace的解決方法
asp下載使用REPLACE來將數(shù)據(jù)庫里讀出來的數(shù)據(jù)替換,如果字段不為空是正常,但如果為空時就出現(xiàn)以下提示:
Microsoft VBScript 運行時錯誤 錯誤 '800a005e'
無效使用 Null: 'Replace'
主要問題就是sqlserver的字段為null,所以不能簡單的為空判斷,只能使用isnull
可以先判斷
if isnull(rs("coutent"))=false then response.write("null") else response.write replace(rs("coutent"),chr(13),"") end if
或者
if rs("coutent")="" then response.write("null") else response.write replace(rs("coutent"),chr(13),"") end if
測試:
if isnull(keyword)=true then keyword=dxy_title
if isnull(descriptions)=true then descriptions=dxy_title
asp replace函數(shù)
Replace語法
Replace(expression, find, replacewith[, compare[, count[, start]]])
Replace 函數(shù)參數(shù)
expression:必選。 字符串表達式 包含要替代的子字符串。
find: 必選。被搜索的子字符串。
replacewith :必選。用于替換的子字符串。
start: 可選。expression 中開始搜索子字符串的位置。如果省略,默認值為 1。在和count 關聯(lián)時必須用
count :可選。執(zhí)行子字符串替換的數(shù)目。如果省略,默認值為 -1,表示進行所有可能的替換。在和 start 關聯(lián)時必須用。
compare: 可選。指示在計算子字符串時使用的比較類型的數(shù)值。有關數(shù)值,請參閱“設置”部分。如果省略,缺省值為 0 ,這意味著必須進行二進制比較。
設置
compare 參數(shù)可以有以下值:
常數(shù) 值 描述
vbBinaryCompare 0 執(zhí)行二進制比較。
vbTextCompare 1 執(zhí)行文本比較。
下面一個就是替換“'”為“''”
Function strReplace(Str) dim tempcheckstr tempcheckstr=Str If Isnull(tempcheckstr) Then strReplace = ""http://這里要注意,如果字符串為空,那replace裝會出錯 Exit Function End If strReplace = Replace(tempcheckstr,"'","''") End Function
到此這篇關于asp提示無效使用 Null: Replace的文章就介紹到這了,更多相關Null Replace內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!
相關文章
asp下用datediff實現(xiàn)計算兩個時間差的函數(shù)
asp下用datediff實現(xiàn)計算兩個時間差的函數(shù)...2007-11-11