-->

asp读取mssql返回的字段,使用自定义截取字符串方法爆类型不匹配

2020-01-06 16:46发布

问题:

asp程序使用的mssql数据库,从数据库读取字段后,使用自定义截取字符串方法是报错如下:

Microsoft VBScript 运行时错误 错误 '800a000d'

调用方法名称lleft:
owen1="新闻公告"
Set rs02=Server.CreateObject("ADODB.RecordSet")
sql="select top 7 news_id,news_Title,check_link,web_link,Creat_Date,hot from news_zx where (BigClassName='"&owen1&"' or BigClassName='询价采购') and (check_tj=1 and check_open=1) order by Creat_Date desc"
rs02.Open sql,conn,1,1
if rs02.eof and rs02.bof then
response.Write("暂时没有记录")
else
k=1
Do While Not rs02.Eof and k<7
response.Write("<p><span class='date'>"&rs02("Creat_Date")&"</span>")
response.write(lleft(rs02("news_Title")))
response.Write("</p>")
rs02.MoveNext
k=k+1
Loop
end if
rs02.close
set rs02=nothing

lleft方法如下:
function lleft(content,lef)
for le=1 to len(content)
if asc(mid(content,le,1))<0 then
lef=lef-2
else
lef=lef-1
end if
if lef<=0 then exit for
next
lleft=left(content,le)
end function

补充:
response.write(lleft(rs02("news_Title")))

rs02("news_Title")类型是string,使用TypeName(rs02("news_Title"))确定类型是string。
但是仍然报错Microsoft VBScript 运行时错误 错误 '800a000d',lleft类型不匹配

回答1:

数据类型转换问题。折腾几天终于完成了。



回答2:

两个问题:
1、参数中指明类型
function lleft(content as String,lef as Integer)
....
end function
2、调用 的时候,你指定其中一个参数,没指定另一个参数lef(看你写的方法这是 要截取的长度吧)?
那调用 应该是:response.write(lleft(rs02("news_Title"),1)) 这样吧,,



标签: asp