我想编一个类模块,作用是接受查询条件然后查询数据返回记录集,却不知怎样去实现,我的做法大概是这样的:'----------------------------------------------------------------------------------------------
'类: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
'-------------------------------------------------------------------------------------------
'运行结果:弹出对话框,内容为空.哪位有空的帮帮忙啊,帮我看这是什么问题,要如何解决?谢谢了!
'类: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
'-------------------------------------------------------------------------------------------
'运行结果:弹出对话框,内容为空.哪位有空的帮帮忙啊,帮我看这是什么问题,要如何解决?谢谢了!
在clsmsg中rs.open连个连接都没带?
做3层的话clamsg中就不要在用rs了,直接在数据访问层定义出数据处理层的对象,将他放入集合中返回出去!