ado问题求救

gus 2000-04-29 02:34:00
有两段代码:

Set conn = Server.CreateObject("ADODB.Connection")
conn.Open "DSN=wolnews;uid=*****;pwd=*****"
Set result=conn.Execute( "Select * From Table_newsAa
where ( News_subject1 like '%华%') or (News_subject2 like '%华%')
or (News_content like '%华%')" )

Set conn = Server.CreateObject("ADODB.Connection")
conn.Open "DSN=wolnews;uid=*****;pwd=*****"
Set result=Server.CreateObject("ADODB.Recordset")
' result.Open "Select * From Table_newsAa where ( News_subject1 like '%华%')
or (News_subject2 like '%华%') or (News_content like '%华%')",conn,1
其中第一段代码返回的result是与库中的内容相符,第二段不对
但第一段的result不能分页显示,怎么办?
大虾们帮帮小弟
...全文
353 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
soberliu 2000-04-30
  • 打赏
  • 举报
回复
对于使用分页技术来说,记录集(Recordset)的Cursor必须是这样的
Recordset的CursorType = AdOpenStatic 才能使用用于分页的PageCount属性设置
对于有的数据库Server来说Recordset的CursorLocation必须是
CursorLocation=AdUseClient才能支持AbsolutePage的属性设置
对于Connection的open方法来讲:其Cursor 是Forward-Only的所以在第1段中是不能分页的。第二段中的open调用方法的写法有一个小错误所以不能返回应该是
Recordset.Open sql,conn,,1
下面是我已经调试好了的一个源程序,请指教:
有疑问的地方请email到 soberliu@263.net
<%@Language = VBScript%>
<%Option Explicit%>
<!-- #include file= "connection.asp"-->
<!-- #include file="adovbs.inc"-->

<%
const intPageSize= 5
dim intCurrentPage,objConn,objSql,strSql
dim intTotalPage, intI
%>
<%
If Request.Form("CurrentPage")=0 then
intCurrentPage =1
Else
intCurrentPage = CInt(Request.Form("CurrentPage"))
select case Request.Form("Submit")
Case "Previous"
intCurrentPage = intCurrentPage -1
Case "Next"
intCurrentPage = intCurrentPage +1
End select
End if
%>

<%
set objConn = Server.CreateObject("ADODB.Connection")
objConn.open connection
set objSql = Server.CreateObject("ADODB.RecordSet")
objSql.CursorLocation = adUseClient
objSql.CursorType = adOpenStatic
objSql.CacheSize = intPageSize
%>
<%
strSql = "SELECT * FROM tblinfdetail WHERE flid in (select flid from tblinfclass)"
rem strSql = "SELECT * FROM tblinfdetail"
objSql.Open strSql,objConn,,adCmdText

objSql.PageSize = intPageSize
if not(objSql.EOF) then objSql.AbsolutePage = intCurrentPage
intTotalPage = objSql.PageCount
%>

<html>
<body>
<%For intI = 1 to objSql.PageSize %>
<%=objSql("title")%><br><%
REM Response.Write ServerHTMLEnCode(objSql("title")&":"&objSql("id"))&"<br>"
objSql.MoveNext()
if objSql.EOF then Exit for
Next
objSql.Close :objConn.Close
set objSql= nothing
set objConn = nothing
%>

<FORM Action="page.asp" Method="Post">
<Input Type="Hidden" Name="CurrentPage" value="<%=intCurrentPage%>">
<%
if intCurrentPage>1 then
%>
<Input Type="Submit" Name="Submit" value="Previous">
<%
End if
%>
<% if intCurrentPage<>intTotalPage then %>
<Input Type="Submit" Name="Submit" value="Next">
<% End if %>

</Form>
</body>
</html>
mxp 2000-04-29
  • 打赏
  • 举报
回复
也可以用
Set conn = Server.CreateObject("ADODB.Connection")
conn.Open "DSN=wolnews;uid=*****;pwd=*****"
Set result=Server.CreateObject("ADODB.Recordset")
result.Open "Select * From Table_newsAa where ( News_subject1 like '%华%')
or (News_subject2 like '%华%') or (News_content like '%华%')",conn,1,1
'加一个1 :)
mxp 2000-04-29
  • 打赏
  • 举报
回复
<!--------------#include file="adovbs.inc"------------------->
mxp 2000-04-29
  • 打赏
  • 举报
回复
第一段执行查询,不是recordset对象,所以不能支持所有分页等方法。
将第二段改为:
<!--------------#include file=adovbs.inc"------------------->
Set conn = Server.CreateObject("ADODB.Connection")
conn.Open "DSN=wolnews;uid=*****;pwd=*****"
Set result=Server.CreateObject("ADODB.Recordset")
result.ActiveConnection=conn
result.source="Select * From Table_newsAa where ( News_subject1 like '%华%')
or (News_subject2 like '%华%') or (News_content like '%华%')"
result.cursortype=adopenstatic
result.locktype=adlockoptimistic
rs.open

28,390

社区成员

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

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