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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing a recordset from COM to VB app

Status
Not open for further replies.

Gazzza

Programmer
Dec 21, 2000
16
AU
Hi

Can anyone tell me is it possible to pass a recordset from a COM to a VB app and how. It seems that I can only pass back standard datatypes like strings, integer ect and not objects or user defined datatypes. I've tried a couple of differnt ways like sending the rs as an adodb.rs and receiving it as an adodb.rs with out any luck.

I want to write a com that has control of the db and client apps that get their data from and write their data to the com. I've never done this before and was wondering what the norm or if there is a norm, prefered or better way of doing this using VB. Should I be loading the data into arrays and passing them back?

Any suggestions on how to tackle this or even the name of a good book that addresses this.

Thanks,

Garry
 
Off the top of my head, the best I can come up with is to have the COM object save (persist) the recordset to a file, then pass the file's path to the VB app as a string. The VB app can then open the persisted recordset, make changes, etc. The main problems with this approach are speed (it may take awhile to save and/or open the recordset, if it is very large) and disk space.

Hope this helps.

-JEB
 
Hi,

This is what I wanted to do, The com can now be set up to interact with the db and the client is being passed a record set for it to display. You will need two projects and a db with the Customers table from Northwind.mdb the connection string is setup for an access 2000 db.

Create a standard exe with a ref to the Activex Data Objects 2.5 library and put this under a button press on a form.

Private Sub Command1_Click()
Dim objServer As Object
Dim rs As Recordset
Dim lnRecCount As Long
Set objServer = CreateObject("DataAccess.clsData")
Set rs = objServer.GetData
If Not rs.EOF Then
rs.MoveLast
rs.MoveFirst
lnRecCount = rs.RecordCount
MsgBox lnRecCount, 64, "Rec Count"
End If
Set objServer = Nothing
End Sub

Create an activex dll with a ref to the Activex Data Objects 2.5 library and name the project DataAccess and the class clsData

Public Function GetData() As Recordset
Dim rs As Recordset
Dim strConnect As String
Set rs = New Recordset
strConnect = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Persist Security Info=False;Data Source=C:\db1.mdb"

With rs
.CursorLocation = adUseClientBatch
.Open "select * from Customers", strConnect, adOpenStatic, _
adLockBatchOptimistic
End With
Set GetData = rs
Set rs = Nothing
End Function

The key points are using adLockBatchOptimistic in the open and cursor location being adUseClientBatch.

Thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top