我编一个记数器,用的是asp + MS Sql server 2000,用到一个表,里面有一个字段,t_counter,是bigint型的,请看下面的程序,运行后总显示如下信息:
----
Microsoft VBScript 运行时错误 错误 800a000d
类型不匹配
/news/counter.asp,行9
-----
源程序:
====
<%
dim m_counter
sqlstr="select n_counter from t_counter"
set conn = Server.CreateObject("ADODB.connection")
conn.open = "dsn=connNews;uid=XXXX;pwd=XXXXX;"
set rs=Server.CreateObject("ADODB.Recordset")
rs.open sqlstr,conn,3,2
m_counter=rs("n_counter")
rs("n_counter")=m_counter+1
rs.update
rs.close
response.write "document.write("&m_counter&");"
%>
请高手指教!!
rs("n_counter")=cint(m_counter)+1
ok?
你不用赋值给其他的变量三,直接加就可以了三,我就是这样做的。
rs("n_counter")=rs("n_counter")+1
将类型转换看看。
在m_counter=rs("n_counter")后检查一下m_counter的变量类型,如果已经是非整型的话,再存进库中肯定会出错,其实最简单的办法就是存进库之前进行强制类型转换,试一下啰!
已经加一了,只不过没有显示出来而已,数据库中已经加了
是null,你怎么加都不行,正确的如下:
rs.open sqlstr,conn,3,2
if isnull(rs("n_counter")) then
rs("n_counter")=0
rs.update
end if
rs("n_counter")=rs("n_counter")+1
rs.update
rs.close