>Here is the code
>
>Dim Rs As ADODB.Recordset
>Dim Str As String
>Dim rstMemory As ADODB.Recordset
>
>'================================================= 'Create an in memory recordset to build the view for the grid
>=================================================
>Set rstMemory = New ADODB.Recordset
>With rstMemory
> .CursorLocation = adUseClient
> .LockType = adLockPessimistic
> .Fields.Append "Entity", adVarChar, 50
> .Fields.Append "EntityCode", adVarChar, 50
> .Fields.Append "Total", adDouble
> .Fields.Append "Price", adDouble
> .Open
>End With
>================================================= 'Fill the In-memory recordset with data
>=================================================
>rstMemory.AddNew
>rstMemory!Entity = "This is the Entity"
>rstMemory!EntityCode = "Code"
>rstMemory.Fields("Total") = 1.23
>rstMemory.Fields("Price") = 4.56
>rstMemory.Update
>
>CnConnection
>
>Str = "Select * From rstMemory"
>Call RsConnection(Str, Rs)
>
>Private Sub CnConnection()
> Set MasterCn = New ADODB.Connection
> MasterCn.Provider = "Microsoft.jet.OLEDB.3.51"
> MasterCn.ConnectionString = " " 'Mdb Path
> MasterCn.Open
>End Sub
>
>Private Sub RsConnection(RsStr As String, RsName As ADODB.Recordset)
> Set RsName = New ADODB.Recordset
> With RsName
> .ActiveConnection = MasterCn
> .CursorType = adOpenDynamic
> .CursorLocation = adUseServer
> .LockType = adLockOptimistic
> .Source = RsStr
> .Open 'At this line it gives me error rstMemory not found
> End With
>End Sub
I really think that I am not on the right way!!!
I have just re-read the entire thread and possibly find the mis-interpretation. Your question was:
I am doing project in VB 6.0 In that i want to create a
temp table(cursor) in memory for storing some fields.
But I don't want to create a temp table (rs) based on
the physically table i.e. i want to create table(cursor)
like we used to do in VFP (Create Cursor . . . . )
I am using ActiveX Data Objects and I have tried for adding some fields
into existing rs with rs.field.append method but it gives
me an error saying that "this request is not applicable in
this context"This is surely due to my VFP ignorance (Create Cursor . . . . ). The syntax I gave you is to create a disconnected recordset (also called in-memory recordset).
Do you simply want to retrieve some fields from a table of a database and show them in a DataGrid?
If so, in a new project, set a reference to ADO, add a DataGrid to the form and paste this code:
Private MasterCn As ADODB.Connection
Private RsName As ADODB.Recordset
Private Sub Form_Load()
Set MasterCn = New ADODB.Connection
With MasterCn
.Provider = "Microsoft.jet.OLEDB.3.51"
.ConnectionString = "D:\Program Files\Microsoft Visual Studio\VB98\nwind.mdb"
.Open
End With
Set RsName = New ADODB.Recordset
With RsName
.ActiveConnection = MasterCn
.CursorType = adOpenStatic
.Source = "SELECT LastName, FirstName, EmployeeID FROM EMPLOYEES ORDER BY LastName, FirstName"
.Open
End With
Set DataGrid1.DataSource = RsName
End Sub
I hope this time that I answer correctly! If not, come back here.
Éric Moreau, MCPD, Visual Developer - Visual Basic MVP
Conseiller Principal / Senior Consultant
Moer inc.
http://www.emoreau.com