asp读取mssql返回的字段,使用自定义截取字符串方法爆类型不匹配
asp程序使用的mssql数据库,从数据库读取字段后,使用自定义截取字符串方法是报错如下:
Microsoft VBScript 运行时错误 错误 '800a000d'
调用方法名称cutstr:
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("<li><span class='date'>"&rs02("Creat_Date")&"</span>")
response.Write(TypeName(rs02("news_Title")))
response.write(cutstr(rs02("news_Title"),5))
response.write(cutstr(Cstr(rs02("news_Title")),5))
response.Write("</li>")
rs02.MoveNext
k=k+1
Loop
end if
rs02.close
set rs02=nothing
cutstr方法如下:
function cutstr(tempstr,lef)'
for le=1 to len(tempstr)
if asc(mid(tempstr,le,1))
lef=lef-2
else
lef=lef-1
end if
if lef
next
if len(tempstr)>le then
cutstr=left(tempstr,le)&"..."
else
cutstr=tempstr
end if
end function
补充:
response.write(cutstr(rs02("news_Title")))
rs02("news_Title")数据库字段类型是nvarchar,使用TypeName(rs02("news_Title"))输出Field。
但是仍然报错Microsoft VBScript 运行时错误 错误 '800a000d',cutstr类型不匹配
试了N多方法不管用,跪求大神指点
你的 newstitle 字段是不是有null值,null值不能len 你应该在cutstr函数里做判断。