一聚教程网:一个值得你收藏的教程网站

最新下载

热门教程

asp语言js写法与vbscript写法

时间:2022-07-02 23:07:46 编辑:袖梨 来源:一聚教程网

连接数据库
VBS:
<%
dim conn
dim dbpath
dim connstr
Set conn =Server.CreateObject("adodb.connection")
dbpath=Server.MapPath("data.mdb")
connstr="Provider=Microsoft.Jet.OLEDB.4.0;Data Source="&dbpath
conn.open connstr
%>

JS:
<%
var conn;
var dbpath;
var connstr;
conn=Server.CreateObject("adodb.connection");
dbpath=Server.MapPath("data.mdb");
connstr="Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+dbpath;
conn.open(connstr);
%>


关闭连接
VBS:
<%'关闭释放记录集
rs.close
set rs = Nothing
conn.close
set conn = Nothing
%>

JS:
<%//关闭释放记录集
rs.close;
rs = null;
conn.close;
conn = null;
%>

输出
VBS:
Response.write ""

JS:
Response.write("");


获取表单对象
VBS:
dim id
id = Request.QueryString("id")

JS:
var id = Request.QueryString("id").item;//重要,js中Request.QueryString是一个对象,要加Item

 

SQL语句日期查询,这个跟VBS的太不相同,相初我郁闷了很久,在网上找了很久才想出下面的语句(这个只写了JS的,VBS的实在不会写)
<%
var rs,sql;
rs = Server.CreateObject("adodb.recordset");
sql = "select * from [count] order by dae desc"
rs.open(sql,conn,1,1)
//实现总访问量
var rst = Server.CreateObject("adodb.recordset");
sqlt="select sum(count) as dt from [count]";
rst.open(sqlt,conn,1,1);
//实现当日访问量
var rsd = Server.CreateObject("adodb.recordset");
sqld="select sum(count) as dd from [count] where day(dae) = '"+((new Date).getDate())+"' and Month(dae) = '"+((new Date).getMonth()+1)+"' and Year(dae) = '"+((new Date).getYear())+"'";
rsd.open(sqld,conn,1,1);
//实现昨日访问量
var rsz = Server.CreateObject("adodb.recordset");
sqlz="select sum(count) as zd from [count] where day(dae) = '"+((new Date).getDate()-1)+"' and Month(dae) = '"+((new Date).getMonth()+1)+"' and Year(dae) = '"+((new Date).getYear())+"'";
rsz.open(sqlz,conn,1,1);
//实现当月访问量
var rsm = Server.CreateObject("adodb.recordset");
sqlm="select sum(count) as dm from [count] where Month(dae) = '"+((new Date).getMonth()+1)+"'";
%>

热门栏目