devxlogo

Handle Advanced Arrays With RDS

Handle Advanced Arrays With RDS

Often you need a data structure similar to a two-dimensioned array or collection, but you need to manipulate it. For example, you need to sort on certain columns, filter certain rows, or find certain values. These functionalities are already available in the ADO Recordset object. The Microsoft Remote Data Services provides a way to store nondatabase data in a recordset using the DataFactory object. This class can help you create in-memory recordsets. Set the reference to Microsoft Remote Data Services Server 2.1 Library:

 ' code forRInMemoryRSOption ExplicitPrivate df As New RDSServer.DataFactoryPrivate vColInfo()Private nTotalCols As LongPublic Function Create() As ADODB.Recordset	If nTotalCols > 0 Then		Set Create = df.CreateRecordSet(vColInfo)	End IfEnd FunctionPublic Sub Clear()	ReDim vColInfo(0)	nTotalCols = 0End SubPublic Sub AddColumn(szName As String, _	nColType As ADODB.DataTypeEnum, Optional _	nColSize As Long = -1, Optional bNullable _	As Boolean = True)	Dim vCol(3)	ReDim Preserve vColInfo(nTotalCols)	vCol(0) = szName	vCol(1) = CInt(nColType)	vCol(2) = CInt(nColSize)	vCol(3) = bNullable	vColInfo(nTotalCols) = vCol	nTotalCols = nTotalCols + 1End SubPrivate Sub Class_Initialize()	nTotalCols = 0End Sub

Use code like this:

 Dim rsMem As ADODB.RecordsetDim RMemRS As new RInMemoryRS' Create Two Column TableRMemRS.AddColumn "Name", adChar, 10, FalseRMemRS.AddColumn "Age", adchar, 10Set rsMem=RMemRS.Create' Now, you can add the data to the "Memory ' Recordset" for examplersMem.AddNew rsMem!Name = "John"rsMem!Age = 15rsMem.UpdatersMem.AddNew rsMem!Name = "Kevin"rsMem!Age = 25rsMem.Update

You can manipulate rsMem like this:

 rsMem.Filter = "Age > 15"rsMem.Sort = "Age ASC"rsMem.Save szFileNamersMem.Find "Name = 'John'"

devx-admin

Share the Post: