asp优化方法

来源:互联网 发布:淘宝商城购物 编辑:程序博客网 时间:2024/04/29 18:04

问一个ASP集合来下载一个值是费时的需计算资源的过程,因为这个操作包含了一系列对相关集合的搜索,这比访问一个局部变量要慢得多。因此,如果打算在页面中多次使用集合中的一个值,应该考虑将其存贮成为一个局部变量
1、声明VBScript变量
2、对URL地址进行编码 response.redirect URL & "?" & var1 & var2 & var3

3、清空对象
<% myDSN="DSN=xur;uid=xur;pwd=xur"
mySQL="select * from authors where AU_ID<100"
set conntemp=server.createobject("adodb.connection")
conntemp.open myDSN
set rstemp=conntemp.execute(mySQL)
if rstemp.eof then
response.write "数据库为空"
response.write mySQL
conntemp.close
set conntemp=nothing
response.end
  end if%>
<%do until rstemp.eof %>
<%
rstemp.movenext
loop
rstemp.close
set rstemp=nothing
conntemp.close
set conntemp=nothing
%>
4、使用字符串建立SQL查询
<%mySQL= ""select * "
mySQL= mySQL & "from publishers"
mySQL= mySQL & "where state='NY'"
response.write mySQL
set rstemp=conntemp.execute(mySQL)
rstemp.close
set rstemp=nothing
%>

5、使用case进行条件选择
6、使用adovbs.inc文件中定义的常量打开记录集
7、避免在使用global.asa文件中进行对象定义

<%
set conn=server.createobject("adodb.connection")
conn.open "driver={microsoft access driver (*.mdb)};dbq="&server.mappath("example3.mdb")
name=request.form("name")
tel=request.form("tel")
message=request.form("message")
exec="insert into guestbook(name,tel,message)values('"+name+"',"+tel+",'"+message+"')"
conn.execute exec
conn.close
set conn=nothing
response.write "记录添加成功!"
%>

if not rs.eof then
 do while not rs.eof
   for i=1 to 12
      sqlstr="select classid,count(classid) from 2s_list where classid="+rsstr(0)+" group by classid"
 

原创粉丝点击