PDA

View Full Version : Create recordset



dhartford
10-24-2008, 12:00 PM
I need to create a recordset then populate data to it. Here is my code:



.....
.....
'add field name to it first
With rstA.Fields
.Append "fName", adChar 'got error.
End With

'then to populate it
With rstA
.AddNew
![fName] = rstB![fName]
.Update
End With



Is this correct way to do? Thanks in advance.

CreganTur
10-24-2008, 01:16 PM
I need to create a recordset then populate data to it. Here is my code:



.....
.....
'add field name to it first
With rstA.Fields
.Append "fName", adChar 'got error.
End With

'then to populate it
With rstA
.AddNew
![fName] = rstB![fName]
.Update
End With



Is this correct way to do? Thanks in advance.

Are you working with an ADO or DAO recordset? Are you appending these records to an existing table, or are you wanting to add them to a brand new table, or is this a temporary recordset where the records are held in memory, but not in a physical table?

dhartford
10-24-2008, 01:25 PM
Are you working with an ADO or DAO recordset? Are you appending these records to an existing table, or are you wanting to add them to a brand new table, or is this a temporary recordset where the records are held in memory, but not in a physical table?

Thanks for your reply.

I'm working with ADO recordset. This is a temporary recordset not physical table.

stanl
10-26-2008, 07:19 AM
Thanks for your reply.

I'm working with ADO recordset. This is a temporary recordset not physical table.

If using ADO, the steps are quite simple. Here are a few snippets from a script I wrote to obtain data from web pages.


'create fields and open Recordset
oRS=CreateObject("ADODB.Recordset")
oRS.Fields.Append "cAccount",202,20 'char
oRS.Fields.Append "cWorkOrder",202,20 'char
oRS.Fields.Append "cWO",203,536870910 'memo
oRS.Fields.Append "iSWO",202,1 'boolean
oRS.Open

..... append rows as required

oRS.AddNew
oRS.Collect("cAccount") = "some data"
oRS.Collect("cWorkOrder") = "some data"
oRS.Update

....persist recordset for later use (as XML)

oRS.Save "c:\temp\myrs.xml",1
oRS.Close()
.... if needed to open later with mspersist provider

oRS.Open "c:\temp\myrs.xml","Provider=MsPersist",1,4,256



by using keyset, batchoptimistic I can udpate to a physical table at a later point just as with a disconnected Recordset. Stan