VB类返回记录集的问题

weisys 2005-10-01 08:58:22


我想编一个类模块,作用是接受查询条件然后查询数据返回记录集,却不知怎样

去实现,我的做法大概是这样的:

'------------------------------------------------------------------

----------------------------
'类:CLSMSG

private mvartitle as string

Property Let Title(ByVal vData As String)
mvartitle = vData
End Property

Property Get Title() As String
Title= mvartitle
End Property

public sub Lookup(id as string)
rs.open "select * from news where id='"& id &"'
mvartitle=rs("title")
rs.close
end sub
'------------------------------------------------------------------

----------------------------
'类CLSMSGS

private list as new collection

private mvarcontent as string

Property Let Content(ByVal vData As String)
mvarcontent = vData
End Property

Property Get Content() As String
Content= mvarcontent
End Property

public sub seachmsg()
dim sql
sql="select * from news"
if Content<>"" then sql=sql & " and content like '%"& content

&"%'"
rs.open sql
do while not rs eof
dim msg as new clsmsg
msg.loopup rs("id")
list.add msg
set msg=nothing
rs.movenext
loop
end sub

public function getfirst() as clsmsg
set getfirst=list.item(1)
end function
'------------------------------------------------------------------

-------------------------------
'引用时

private sub command1_Click()
dim ms as new clsmsgs
ms.content="新闻"
ms.getlist
set ms1=ms.getfirst()
msgbox ""& ms1.Title &""
set ms1=nothing
set ms=nothing
end sub
'------------------------------------------------------------------

-------------------------
'运行结果:弹出对话框,内容为空.

哪位有空的帮帮忙啊,帮我看这是什么问题,要如何解决?谢谢了!


...全文
110 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

1,216

社区成员

发帖
与我相关
我的任务
社区描述
VB 数据库(包含打印,安装,报表)
社区管理员
  • 数据库(包含打印,安装,报表)社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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