Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

COM method returning Array/ Variant recordset

Status
Not open for further replies.

DKL01

Programmer
Sep 14, 2000
233
US
Hello All:

I am wondering how to write and method which returns an array or variant recordset.

I need to write a method which connects to database, process the record set and returns the variant recordset.

Thanks
Dilip
 
Here is an example of one way to do it. I have these procedures in an active-x dll server.
Code:
Public Sub OpenRecordset(ByRef rs As ADODB.Recordset, ByVal sql As String)
    Set rs = New ADODB.Recordset
    rs.Open sql, m_cn, adOpenKeyset, adLockPessimistic, adCmdText
End Sub

Public Sub CloseRecordset(ByRef rs As ADODB.Recordset)
On Error Resume Next
    rs.Close
On Error GoTo 0
    Set rs = Nothing
End Sub
If takes as parameters a refrence to a recordset and the sql string to generate that recordset (I have removed the code that adjusts that querey string as it was not relevant to your question). So, to call it from a program you would use code like this (assuming the object varable that points to this dll server is SQLUtils).

Code:
Dim TestRS As ADODB.Recordset 
Dim sql As String 

sql = &quot;select * from testtable where rec < 5&quot; 

SQLUtils.OpenRecordset TestRS, sql 

While Not TestRS.EOF 
    'work with the returned recordset here 
Wend 

SQLUtils.CloseRecordset TestRS

Since the rs variable is being passed into the procedures in the .dll server ByRef, the server actually just gets a pointer to the memory location of the TestRS variable in the client program. All changes it makes to it's local rs variable are actually being made to the TestRS in your client program.
HTH Ruairi

Could your manufacturing facility benefit from real time process monitoring? Would you like your employees to be able to see up to the minute goal and actual production?
For innovative, low cost solutions check out my website.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top