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