"Paulo Roberto" wrote in message
> Hi, I have a client recordset returned via VB6. I'd like to know if it can
> be inserted to a phisical table on MS SQL SERVER containing the same
> fields...? It'd be like a "INSERT SELECT", but the source (select) would
> come from this adodb.recordset.
>
> I'd like to avoid looping every line of the recordset and generating
> "insert into" instructions....
>
> Thanks !
One fairly easy way is to persist the recordset to XML (see the Save
method), alter the XML, open a new recordset on the altered XML, connect it
to a SQL Server and call UpdateBatch. Instead of:
<rs:data>
<z:row field1="value" field2="value" [...] />
<z:row field1="value" field2="value" [...] />
[...]
</rs:data>
it becomes:
<rs:data>
<rs:insert>
<z:row field1="value" field2="value" [...] />
<z:row field1="value" field2="value" [...] />
[...]
<rs:insert>
</rs:data>
There are some conditions, no values can be present for identity columns,
computed or derived columns or columns that are inherently read-only for any
other reason. Also, in the schema section you may need to fixup the values
of the basetable and basecatalog attributes as appropriate.
More, the recordset itself must be writable (attribute/value
rs:updatable='true' present in the s:ElementType node) as well as each
column for which a value is supplied (attribute/value rs:writeunknown='true'
present in each s:AttributeType node.)
Note that it is possible to change the XML, as long as the change is valid
in the context of the server. For example, a recordset returned by calling
connection or command .Execute, or by executing a stored procedure as if it
were a method of a connection object is, to ADO, read-only, and this is
reflected in XML when it is persisted. However, this does not necessarily
mean that the underlying data elements on the server cannot be written. A
writable recordset can be created by manipulating the XML, provided those
manipulations are not invalid to the server.
It all sounds involved (perhaps because it is, in fact, quite involved) but
once you've worked out the details for your specific recordset[s] it's a
pretty simple transformation.
Good Luck,
Mark
>> Stay informed about: ADODB.RecordSet