Microsoft KB Archive/193331

= How To Create a Recordset from a Variant Array with RDS =

Article ID: 193331

Article Last Modified on 3/14/2005

-

APPLIES TO


 * Microsoft Remote Data Services 2.0
 * Microsoft Remote Data Services 1.5
 * Remote Data Service for ADO 2.0
 * Microsoft Remote Data Services 2.1
 * Remote Data Service for ADO 2.5
 * Remote Data Service for ADO 2.6

-



This article was previously published under Q193331



SUMMARY
This article describes how to pass a variant array using the CreateRecordset method of the RDSServer.Datafactory and RDS.DataControl.

The article assumes that you have the Microsoft Data Access Components (MDAC) components installed on your computer. Microsoft Data Access Components can be found at that following Web URL:

http://msdn.microsoft.com/dataaccess



MORE INFORMATION
The following code creates a Visual Basic ActiveX DLL that contains two methods. One method generates the recordset and the other method updates the recordset.

The client program that is created in Visual Basic tests the functionality of the component.

You can also use the RDS.Datacontrol to create a recordset from a variant array.

Step-by-Step Example
 Start Visual Basic and create a business object (ActiveX DLL) project. Name the ActiveX DLL Project RDSRecordset. Rename the default class name (class1) to MyClass. Add a project reference to the Microsoft Remote Data Services Server Library and the Microsoft ActiveX Data Objects Library.  Paste the following code into the Declarations section of the class: 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  Compile and create the RDSRecordset.dll file. Create the Visual Basic client application, RDSRecordsetClient. Create a Standard .exe project. Add a reference to the RDSRecordset.dll file and to the Microsoft ActiveX Data Objects Library.</li>  Place the following objects on the default form: <pre class="fixed_text">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. </li>  Paste the following code into the General Declarations of the frmMain form: 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 </li> Run the client program.</li></ol>

<div class="references_section">