找回密码
 注册
搜索
查看: 6508|回复: 0

VB类返回记录集的问题

[复制链接]
发表于 2005-10-1 08:48:57 | 显示全部楼层 |阅读模式
  我想编一个类模块,作用是接受查询条件然后查询数据返回记录集,却不知怎样

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

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

----------------------------
  '类: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
'------------------------------------------------------------------

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

哪位有空的帮帮忙啊,帮我看这是什么问题,要如何解决?谢谢了!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|手机版|小黑屋|宁德市腾云网络科技有限公司 ( 闽ICP备2022007940号-5|闽公网安备 35092202000206号 )

GMT+8, 2025-6-19 03:28 , Processed in 0.014530 second(s), 15 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表