Browse DevX
Sign up for e-mail newsletters from DevX

Tip of the Day
Language: Visual Basic
Expertise: Advanced
Apr 27, 2000



Building the Right Environment to Support AI, Machine Learning and Deep Learning

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 forRInMemoryRS
Option Explicit
Private df As New RDSServer.DataFactory
Private vColInfo()
Private nTotalCols As Long
Public Function Create() As ADODB.Recordset
	If nTotalCols > 0 Then
		Set Create = df.CreateRecordSet(vColInfo)
	End If
End Function
Public Sub Clear()
	ReDim vColInfo(0)
	nTotalCols = 0
End Sub
Public 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 + 1
End Sub
Private Sub Class_Initialize()
	nTotalCols = 0
End Sub
Use code like this:
Dim rsMem As ADODB.Recordset
Dim RMemRS As new RInMemoryRS
' Create Two Column Table
RMemRS.AddColumn "Name", adChar, 10, False
RMemRS.AddColumn "Age", adchar, 10
Set rsMem=RMemRS.Create
' Now, you can add the data to the "Memory 
' Recordset" for example
rsMem!Name = "John"
rsMem!Age = 15
rsMem!Name = "Kevin"
rsMem!Age = 25
You can manipulate rsMem like this:
rsMem.Filter = "Age > 15"
rsMem.Sort = "Age ASC"
rsMem.Save szFileName
rsMem.Find "Name = 'John'"
Rajesh Pohuja
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date