VBScript数组赋值类型不匹配

来源:百度知道 编辑:UC知道 时间:2024/06/04 10:32:14
function checkip(ip)
dim ipArray(100)
sql="Select ip from Candidate where id="&id
Set rs2=cnn.execute(sql)
ipArray=split(rs2,",")=================这行提示类型不匹配
For i = 0 To UBound(ipArray)
if ip=ipArray(i) then
checkip=true
else
checkip=false
end if
next
end function

怎么会类型不匹配呢

rs2不是一个字符串变量。它是一个记录集对象,你的语句可以简化为

function checkip(ip)
dim ipArray(100)
sql="Select ip from Candidate where id="&id
Set rs2=cnn.execute(sql)
do while not rs2.eof
if ip=rs2(0) then
checkip=true
else
checkip=false
end if
rs2.movenext
loop
rs2.close
end function

因为你的rs2是对记集录对象..
你得把里面的数据取出来.

Split(str1,str2)函数的第一个参数必须是字符串,而且字符串有包含第二个参数的字符。

在你的代码中rs2是一个recordset的数据类型,需要字符转换,另外验证是否返回数据不为空。修改部分代码如下:
dim strtmp as String
dim ipArray(100)
sql="Select ip from Candidate where id="&id
Set rs2=cnn.execute(sql)
if rs2.recordcount=1 then
strtmp=cstr(rs2.fields(0).value)
ipArray=split(strtmp,",")

end if