VB+ASP+MTS问题请教

jackyrong 2001-08-14 12:07:33
用VB+ASP+MTS做了个查询的程序,过程如下,但通不过,不知道
什么原因,敬请指教。
1)查询页面是输入要查询的关键字(keyword),之后用下拉框选择查询条件(kind)比如按书名,按作者,出版社等,之后提交(SEARCH.ASP)
进行查询,查询是分页显示的。
2)用VB做的MTS组件如下,能成功编译并注册到MTS上,
Option Explicit
Private m_keyword1 As Variant
Private m_kind As String
Private m_bookid As Integer
Private m_price As Double
Private m_writer As String
Private m_press As String
Public Property Let keyword1(ByVal vNewValue As Variant)
m_keyword1 = vNewValue
End Property
Public Property Let kind(ByVal vNewValue As Variant)
m_kind = vNewValue
End Property



Public Function ListCourses(bookid As Variant, bookname As Variant, price As Variant, writer As Variant, press As Variant)
On Error GoTo ErrorHandle
Dim strSQL As String
Dim objContext As ObjectContext
Set objContext = GetObjectContext()
' 建立事务性组件
Dim objADOConn As ADODB.Connection
' 利用ADO访问数据库
Dim objrs As ADODB.Recordset
Set objADOConn = New ADODB.Connection
With objADOConn
.ConnectionTimeout = 10
.ConnectionString = "Provider=SQLOLEDB.1;dsn=yi;UserID=sa;Initial Catalog=trade;view=vbook"
' 通过OLEDB建立与数据库的连接
.Open
End With
Set objrs = New ADODB.Recordset
strSQL = "select * from vbook where " & m_kind & " =' %" & m_keyword1 & " %' "
objrs.Open strSQL, objADOConn

' 进行数据库查询

bookid = objrs("bookid")
bookname = objrs("bookname")
writer = objrs("writer")
press = objrs("press")
price = objrs("price")
objrs.MoveNext
'Set ListCourses = objrs
objContext.SetComplte
' 若事务成功完成,则提交该事务
objADOConn.Close
Set objADOConn = Nothing
Set objrs = Nothing
strSQL = ""
'关闭数据库连接,释放所有对象
Exit Function
ErrorHandle:
objContext.SetAbort
Set ListCourses = Nothing
' 若事务失败,则回滚事务
End Function
Public Function iseof() As Boolean

iseof = objrs.EOF
End Function
3)搜索的ASP页面如下(节选有用部分)
<%
keyword=request("keyword")
kind=request("kind")

dim objResult
set objResult=Server.CreateObject("find.search")
objResult.kind=request("kind")
objResult.keyword1=request("keyword")
set rs=Server.CreateObject("ADODB.Recordset")
'dim scores as recordset
dim bookid
dim bookname
dim price
dim writer
dim press
while not objresut.iseof=false
objResult.listcourses bookid,bookname,price,writer,press


<tr>
<td><%=bookid%></td>
<td><%=bookname%></td>
...............
....之后是有关的分页显

但最后程序运行后,明明是数据库有的记录却找不到,但程序没
出错提示,为什么呢?
...全文
151 点赞 收藏 17
写回复
17 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
jackyrong 2001-08-23
这个问题我已经自己解决了。
回复
coolstar 2001-08-23
不是解决了吗?不给分呀
回复
jackyrong 2001-08-16
怎么很少人搞用三层做ASP的?
回复
jackyrong 2001-08-16
还是没人能解决我的问题呀
回复
tripofdream 2001-08-15
为了通用,最好是将SQL语句作参数
Public Function ListCourses(byVal strSql as String) as ADODB.Recordset
......
End Function
回复
tripofdream 2001-08-15
直接返回recordset(如:
Public Function ListCourses(bookid As Variant, bookname As Variant, price As Variant, writer As Variant, press As Variant) as ADODB.Recordset
),查询出错时返回nothing
回复
tripofdream 2001-08-15
重写组件
回复
jackyrong 2001-08-15
哦,没人理我的?
回复
jackyrong 2001-08-15
TRIPOFDREAM的做法试过啦,不行的
回复
hydnoahark 2001-08-15
将页数作为一个参数传入COM,COM只返回相应的纪录
回复
jackyrong 2001-08-14
我不大知道如何在VB中单步调试ACTIVE DLL,请指点
回复
neweb 2001-08-14
》select * from vbook where " & m_kind & " =' %" & m_keyword1 & " %' "

你把上面的语句在数据库里跑过吗?

select * from vbook where m_kind like '%somestring%'

回复
superlink 2001-08-14
while not objresut.iseof=false判断条件有问题
回复
hydnoahark 2001-08-14
>>Public Function iseof() As Boolean
objRs是Public Function ListCourses中的一个局部对象,在Public Function iseof() 中不能使用这个对象
回复
jackyrong 2001-08-14
那应该如何写呢?
回复
tripofdream 2001-08-14
在ASP程序中最好也加上<%option explicit%>,这样比较容易发现变量名写错
回复
tripofdream 2001-08-14
1.select * from vbook where " & m_kind & " like ' %" & m_keyword1 & " %' "
2.while not objresut.iseof=false,objresult写错了.

回复
相关推荐
发帖
ASP
创建于2007-09-28

2.8w+

社区成员

ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
申请成为版主
帖子事件
创建了帖子
2001-08-14 12:07
社区公告
暂无公告