Create a Recordset in Memory

Create a Recordset in Memory

Post by Ronald K. Re » Sun, 13 Jun 1999 04:00:00



I was wondering does anyone know how to create a recordset in memory, or know of a  website that
would show me how to do this sort of procedure.

T.I.A.,

Ronald K. Rex

 
 
 

Create a Recordset in Memory

Post by VB-Joke » Mon, 14 Jun 1999 04:00:00


Ronald,

I think what you are looking for is called Creatable Recordsets.

This is some sample code I got from the MDAC SDK 2.1 help files:

Dim Rst As New ADODB.Recordset
Rst.CursorLocation = adUseClient

'Add Some Fields
Rst.Fields.Append "dbkey", adInteger
Rst.Fields.Append "field1", adVarChar, 40, adFldIsNullable
Rst.Fields.Append "field2", adDate

'Create the Recordset
Rst.Open , , adOpenStatic, adLockBatchOptimistic

'Add Some Rows
Rst.AddNew Array("dbkey", "field1", "field2"), _
   Array(1, "string1", Date)
Rst.AddNew Array("dbkey", "field1", "field2"), _
   Array(2, "string2", #1/6/1992#)

'Look at the values - a value of 1 for status column = newly record
Rst.MoveFirst
Debug.Print "Status", "dbkey", "field1", "field2"
While Rst.EOF <> True
   Debug.Print Rst.Status, Rst!dbkey, Rst!field1, Rst!field2
   Rst.MoveNext
Wend

'Commit the rows without ActiveConnection set resets the status bits
Rst.UpdateBatch adAffectAll

'Change the first of the two rows
Rst.MoveFirst
Rst!field1 = "changed"

'Now look at the status, first row shows 2 (modified row),
'second shows 8 (no modifications)
'Also note that the OriginalValue property shows the value
'before the modification
Rst.MoveFirst
While Rst.EOF <> True
   Debug.Print
   Debug.Print Rst.Status, Rst!dbkey, Rst!field1, Rst!field2
   Debug.Print , Rst!dbkey.OriginalValue, _
      Rst!field1.OriginalValue, Rst!field2.OriginalValue
   Rst.MoveNext
Wend

--
Regards

VB-Joker
Carsten Thomsen/MCSE

PLEASE post ALL replies to the newsgroup(s) so we can all benefit from the
discussion!


Quote:> I was wondering does anyone know how to create a recordset in memory, or

know of a  website that
Quote:> would show me how to do this sort of procedure.

> T.I.A.,

> Ronald K. Rex