日期:2010-05-17  浏览次数:21022 次

用application和session做的简单计数器
<%
if isempty(session("conn")) then
application.lock
set counterfile=server.createobject("scripting.filesystemobject")
set temp=counterfile.opentextfile(server.mappath("count.txt"),1,true,false)
num=temp.readline
if num=empty then num=1
application("count")=num
application("count")=application("count")+1
temp.close
end if
%>
<center><h1>访客人数:<font color=red><%=application("count")%></font></h1>
<%
set counterfile=server.createobject("scripting.filesystemobject")
set temp=counterfile.createtextfile(server.mappath("count.txt"),true,false)
temp.writeline(application("count"))
temp.close
application.unlock
%>

###########################################################################

If Then 程序语句 End if 如
<%
score=request("score")
if not isnumeric(score) then
m="请输入数字"
elseif score="" then
m="请输入数据"
elseif score>=60 and score<=100 then
m="及格"
elseif score>100 or score<0 then
m="请输入0---100之间的数"
else
m="不及格"
end if
%>

cookies:

<%
response.buffer=true ' 因是没有在服务器下载数据前就进行了交换,所以用缓冲区来装下载的数据
var=request.cookies("var")
if var="" then var=empty '因为""不可与数值运算
response.write"开始var="&var&"<br>"
var=var+10
response.write"结束var="&var&"<br>"
response.cookies("var")=var
response.cookies("va").expires="2004/3/31/" '设定有效期
%>

###########################################################################

称动、复制、删除文件

<%
set fs=server.createobject("scripting.filesystemobject")
source=server.mappath("1/1.txt")
target=server.mappath("1.txt")
on error resume next
fs.movefile source,target 'movefile换在deletefile\copyfile
if err.number=53 then
response.write source&"文件不存在"
response.end
elseif err.number=70 then
response.write target&"文件为只读或锁"
response.end
elseif err.nuber<>0 then
response.write"other="&err.number
response.end
end if
%>

##########################################################

读取文本内容
<%
set fs=server.createobject("scripting.filesystemobject")
file=server.mappath("1/1.txt")
set txt=fs.opentextfile(file,1,true)
if not txt.atendofstream then
line=txt.readline'可换成readall
response.write line&"<br>"
end if
%>

############################################

SERVER & Request]
<%=server.htmlencode("<i>原码输出</i>")%>
<%=request.servervariables("local_addr")%>'本地IP
<%=request.servervariables("remote_addr")%>'Client 端IP

连接access数据库的两种方法:
1、<% Set CN = Server.CreateObject("ADODB.Connection"
CN.Open "Driver={Microsoft Access Driver (*.mdb)};DBQ="&Server.MapPath("message.mdb")
Set rs=Server.CreateObject("ADODB.Recordset")
%>
2、<%  Set con = Server.CreateObject("ADODB.Connection")
  DBPath = Server.MapPath("bbs.mdb")
con.Open "provider=microsoft.jet.oledb.4.0;data source="&DBPath
  Set rs=Server.CreateObject("ADODB.Recordset")
%>

##########################################################################

数据表打开的几种方法
1、SQL = "Select * From 数据表 Where 主编号=" & request("ID")
RS.Open SQL,con,1,3
2、RS.Open "数据表",con,1,3
3、RS.Open "Select * from student",con,1,3

读取数据库数据的方面

1、<%=RS(0).name%> '读取第一栏的表头名称
2、<%=RS(1).value%> '读取第二栏的里的内容
3、<%=Rs.Fields(1).Value%> '同上
4、Rs.recordcount '总记录数
5、Rs.fields.Count '有几个栏位

###########################################################################
如读取表中的数据:
<%
Num=0
For Itemline=0 To Rs.recordcount-1 'recordcount-1 不会移出最后一笔记录
Response.Write "<TR>"
   For I=0 To Rs.f