问题已解决,十分感谢高手指点.现把代码贴上,供大家参考。
<%
dim conn
dim connstr
on error resume next
connstr="DBQ="+server.mappath("../../#User.mdb")+";DefaultDir=;DRIVER={Microsoft Access Driver (*.mdb)};"
set conn=server.createobject("ADODB.CONNECTION")
if err then
err.clear
else
conn.open connstr
if err then
err.clear
end if
end if
%>
用上面方法打开数据库,“nos”可用以设为文本型就可以计算,那怕是中文件字,但不能统计数字型,用sql="select sum(nos3) as sumval from scunews where nos3=1 "一样不能计算数字型“nos”.还有用下面的也是不行.
<% set rs=server.createobject("adodb.recordset")
sql="select * from users where nos='1' "
rs.open sql,conn,1,1
response.write rs.recordcount
%>
以下代码可以计算数字型字段“nos”,一定要用最后一种方法打开数据库。用上面第一种就不行。
<%
set rs=server.CreateObject("adodb.recordset")
sql="select id from scunews where nos1=1"
rs.open sql,cn,1,1
s01=rs.recordcount
response.write rs.recordcount
rs.close
set rs=nothing
%>
<%
Response.Buffer=True
'''''''''''''''''''''''''''''' Access数据库 '''''''''''''''''''''''''''''''''''''''''''''''''''''''''
datapath ="" '数据库目录的相对路径
datafile ="../../mdb/#User.mdb" '数据库的文件名
connstr="Provider=Microsoft.Jet.OLEDB.4.0;Data Source="&Server.MapPath(""&datapath&""&datafile&"")
'Connstr="DBQ="&server.mappath(""&datapath&""&datafile&"")&";DRIVER={Microsoft Access Driver (*.mdb)};"
SqlNowString="Now()"
SqlChar="'"
ver="5.13a"
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
On Error Resume Next
Set cn=Server.CreateObject("ADODB.Connection")
cn.open ConnStr
set rs=Server.CreateObject("ADODB.Recordset")
If Err Then
err.Clear
Set Conn = Nothing
Response.Write "数据库连接出错,请检查连接字串。"
Response.End
End If
%>