Article ID: 193331
Article Last Modified on 3/14/2005
Dim ADF As New RDSServer.DataFactory
Dim rs As New ADODB.Recordset
Public Function GetRS() As Variant
Dim ColInfo(1), c0(3), c1(3)
c0(0) = "Name" ' Column name.
c0(1) = CInt(129) ' Column type (129 = adChar).
c0(2) = CInt(40) ' Column size.
c0(3) = False ' Is the column nullable?
c1(0) = "Age" ' Column name.
c1(1) = CInt(3) ' Column type (3 = adInteger).
c1(2) = CInt(-1) ' Column size.
c1(3) = True ' Is the column nullable?
' Add the columns to the recordset definition.
ColInfo(0) = c0
ColInfo(1) = c1
' Actual creation of Recordset from the variant array.
Set rs = ADF.CreateRecordSet(ColInfo)
rs.AddNew
rs(0) = "Tom"
rs(1) = 20
rs.Update
rs.AddNew
rs(0) = "anotherTom"
rs(1) = 21
rs.Update
Set GetRS = rs
End Function
Public Function ProcessRs(rs As Variant) As Variant
' Add another row to the recordset and send it back to the client.
rs.AddNew
rs(0) = "YetanotherTom"
rs(1) = 30
rs.Update
Set ProcessRs = rs
End Function
Object Name Caption
=========================================================
List box lstFields
Command button cmdGetRs Get data.
Command button cmdUpdate Update data.
Command button cmdSendData Send data.
Command button cmdEnd E&xit
Form frmMain Creating recordsets without
connecting to a database.
Dim myObj As New RDSRecordset.myClass
Dim myrs As New ADODB.Recordset
Private Sub cmdGetRS_Click()
' Call the method of our object to get the recordset.
Set myrs = myObj.GetRS
DisplayData
cmdGetRS.Enabled = False
cmdUpdate.Enabled = True
End Sub
Private Sub cmdSendData_Click()
'Call another method on your object to update the recordset
' and return it back.
Set myrs = myObj.ProcessRs(myrs)
DisplayData
ReInitializeCmd
End Sub
Private Sub cmdUpdate_Click()
' Update the local recordset.
cmdSendData.Enabled = True
myrs.MoveFirst
myrs.Fields(0).Value = "Changed1"
myrs.Update
DisplayData
cmdUpdate.Enabled = False
End Sub
Private Sub Form_Load()
Set myrs = myObj.GetRS
ReInitializeCmd
End Sub
Private Sub DisplayData()
myrs.MoveFirst
lstFields.Clear
Do While Not myrs.EOF
lstFields.AddItem myrs.Fields(0).Value
myrs.MoveNext
Loop
End Sub
Public Sub ReInitializeCmd()
cmdSendData.Enabled = False
cmdUpdate.Enabled = False
cmdGetRS.Enabled = True
End Sub
Private Sub cmdEnd_Click()
Set myObj = Nothing
Set myrs = Nothing
End
End Sub
Keywords: kbhowto kbdatabase KB193331