Classes and recordsets

B

Boardrider

Hi,

Assuming I create an object as below

<%
Dim objMainItem
Set objMainItem = New ItemContent
objMainItem.item_id = 1
objMainItem.Open()
%

and the class ItemContent creates a recordset based on the item_id
passed in.
Each item record contains the fields (header,label,content). I would
like to reference the fields in the following format

<%= objMainItem.header %

Is this possible?

Many thanks,

s/.
 
R

Ray at

Yes, you can do that if you want to. Something like:


<%
Dim objMainItem
Set objMainItem = New ItemContent
objMainItem.item_id = 1
objMainItem.Open()
Response.write objMainItem.Header
Set objMainItem = Nothing



Class ItemContent
Private iItemID, sHeader

Public Sub Open()
If iItemID <> "" Then
Dim oADO, rs
Set oADO = Server.CreateObject("ADODB.Connection")
oADO.Open "Your connection string here"
Set rs = oADO.Execute("SELECT [Header] FROM [Table1] WHERE [item_id]=" &
iItemID)
If Not rs.EOF Then
sHeader = rs.Fields.Item(0).Value
End If
rs.Close : Set rs = Nothing
oADO.Close : Set oADO = Nothing
End If
End Sub

Public Property Let item_id(id)
iItemID = id
End Property

Public Property Get Header()
Header = sHeader
End Property
End Class
%>

You could add other private vars and "public property gets" if you have more
than one column to retreive.

Ray at work
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,023
Latest member
websitedesig25

Latest Threads

Top