这段代码谁能帮我优化一下,我总是感觉有问题!执行是能执行。但是呢。有点慢啊。谢谢啦

pencil_xx 2001-12-27 10:29:55
<%
Sqlsearch=Trim(request("sqlsearch"))
ProvinceID=Cint(request("ProvinceID"))
sqlprovince="select CityID from tblCity where ProvinceID=" & ProvinceID & " order by ProvinceID"
'response.write sqlprovince
set rs=server.createobject("adodb.recordset")
rs.open sqlprovince,conn
%>
<table width="760" border="0" cellspacing="1" cellpadding="1" align="center" class="homeleft1">
<%do while not rs.eof %>
<%if sqlsearch="ok" then
sqlcity="select FactoryName,FID,FactoryType,FactoryRemark from tblFactory where CityID=" & rs("CityID")
else
sqlcity=sqlsearch & " and CityID=" & rs("CityID")
end if
'response.write sqlcity
set RsCity=conn.execute(sqlcity)
if RsCity.eof then
else
do while not RsCity.eof
%>
<tr bgcolor="#FFFFFF" bordercolor="#FFFFFF">
<td width="332" class="infomain"><a href='productremark.asp?FactoryID=<%=RsCity("FID")%>'>
<%=RsCity("FactoryName")%> </a> </td>
<td width="332" class="infomain">
<%=RsCity("FactoryType")%> </td>
<td width="239" class="infomain">
<%if trim(RsCity("FactoryRemark"))="" or isnull(RsCity("FactoryRemark")) then%>
厂家介绍:暂为空
<%else%>
<%=RsCity("FactoryRemark")%>
<%end if%>
</td>
</tr>

<% RsCity.MoveNext
loop
end if
RsCity.close
set Rscity=nothing
%>

<%rs.movenext
loop%>
<%
rs.close
set rs=nothing
%>
...全文
126 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
balloy 2001-12-27
  • 打赏
  • 举报
回复
<%
Sqlsearch=Trim(request("sqlsearch"))
ProvinceID=Cint(request("ProvinceID"))
sqlprovince = "select C.CityID, F.FactoryName, F.FID, F.FactoryType, F.FactoryRemark from tblCity C, tblFactory F where C.CityId = F.CityId And C.ProvinceID=" & ProvinceID & " order by C.ProvinceID"

set rs=server.createobject("adodb.recordset")
rs.open sqlprovince,conn
%>
<table width="760" border="0" cellspacing="1" cellpadding="1" align="center" class="homeleft1">
<%do while not rs.eof %>
<tr bgcolor="#FFFFFF" bordercolor="#FFFFFF">
<td width="332" class="infomain"><a href='productremark.asp?FactoryID=<%=rs("FID")%>'>
<%=rs("FactoryName")%> </a> </td>
<td width="332" class="infomain">
<%=rs("FactoryType")%> </td>
<td width="239" class="infomain">
<%if trim(rs("FactoryRemark"))="" or isnull(rs("FactoryRemark")) then%>
厂家介绍:暂为空
<%else%>
<%=rs("FactoryRemark")%>
<%end if%>
</td>
</tr>

<% rs.MoveNext
loop
end if
Rs.close
set rs=nothing
%>
bblook 2001-12-27
  • 打赏
  • 举报
回复
1。对于第一个记录集也用成
set rs=conn.execute(sqlprovince)
会快一点
这样的话可以少打开一个连接,多记录集时,比较有效。
2。还有就是不要把createobject 放到循环中。
3。使用脱机记录集会比较快!
With rs
.CursorLocation = adUseClient
.CursorType = adOpenForwardOnly
.LockType = adLockBatchOptimistic
.ActiveConnection = cn
.Open SQL
.ActiveConnection = Nothing
End With




cavalier_27 2001-12-27
  • 打赏
  • 举报
回复
用嵌套,关闭不用的rs
pencil_xx 2001-12-27
  • 打赏
  • 举报
回复
感觉是有点快了。

但是呢。我用了两个记录集

是不是慢的原因
pencil_xx 2001-12-27
  • 打赏
  • 举报
回复
要多少是多。

我给你加
25475360 2001-12-27
  • 打赏
  • 举报
回复
一开始默认的都是20分嘛 ,唉,本来是交流的地方,现在倒成了赚分的地方了
kjijian 2001-12-27
  • 打赏
  • 举报
回复
只给这么少的分
25475360 2001-12-27
  • 打赏
  • 举报
回复
老兄,程序是不要改了,但我有一办法可以让你的快一点.

网页上的显示是按表格来显示的,当一个表格没有读完时,它是不会显示的,所以我建议你

多用小表,不要在最外面套大表.

比如:

<TABLE>
...循环
<TR>
...循环
</TR>
</TABLE>
改成
<TABLE>....</TABLE>
...循环
<TABLE>....</TABLE>
...循环
<TABLE>....</TABLE>
在表格中设置为间距为0是看不出来的.

或者:
每显示20条记录就成一个表格,快得很.

kjijian 2001-12-27
  • 打赏
  • 举报
回复
太小气,不想看了,
pencil_xx 2001-12-27
  • 打赏
  • 举报
回复
我已经按照上面各们说的改了
只是bblook(比比路克) 说的
3。使用脱机记录集会比较快!
With rs
.CursorLocation = adUseClient
.CursorType = adOpenForwardOnly
.LockType = adLockBatchOptimistic
.ActiveConnection = cn
.Open SQL
.ActiveConnection = Nothing
End With


我不知道如果在我这里面用上。可以指点指点吗
<%
Sqlsearch=Trim(request("sqlsearch"))
ProvinceID=Cint(request("ProvinceID"))
sqlprovince="select CityID from tblCity where ProvinceID=" & ProvinceID & " order by ProvinceID"
'response.write sqlprovince
set rs=conn.execute(sqlprovince)
%>
<%if rs.eof then
response.redirect "blank.asp"
end if
%>
<%do while not rs.eof %>
<%if sqlsearch="ok" then
sqlcity="select FactoryName,FID,FactoryType,FactoryRemark from tblFactory where CityID=" & rs("CityID")
else
sqlcity=sqlsearch & " and CityID=" & rs("CityID")
end if
'response.write sqlcity
set RsCity=conn.execute(sqlcity)
if RsCity.eof then
else
do while not RsCity.eof
%>
<table width="760" border="0" cellspacing="1" cellpadding="1" align="center" class="homeleft1">
<tr bgcolor="#FFFFFF" bordercolor="#FFFFFF">
<td width="332" class="infomain"><a href='productremark.asp?FactoryID=<%=RsCity("FID")%>'>
<%=RsCity("FactoryName")%> </a> </td>
<td width="332" class="infomain">
<%=RsCity("FactoryType")%> </td>
<td width="239" class="infomain">
<%if trim(RsCity("FactoryRemark"))="" or isnull(RsCity("FactoryRemark")) then%>
厂家介绍:暂为空
<%else%>
<%=RsCity("FactoryRemark")%>
<%end if%>
</td>
</tr>
</table>

<% RsCity.MoveNext
loop
end if
RsCity.close
set Rscity=nothing
%>

<%rs.movenext
loop%>
<%
rs.close
set rs=nothing
%>

28,406

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧