Updating db by connecting a disconnected recordset in ADO

Hello,

I have two questions.
1) How (in c++) do you disconnect and reconnect via ActiveConnection in
   ADO.

The code I tried follows.  I also tried variations of this code
and I didn't get any errors, but it did not update the database
with the new row.

    _RecordsetPtr   pRs("ADODB.Recordset");
    pRs->CursorLocation = adUseClient;
    hResult = pRs->Open((variant_t)"VEH", m_spConnDispPtr,
        adOpenStatic, adLockBatchOptimistic, adCmdTable);

    //* disconnect
    hResult = pRs->putref_ActiveConnection(NULL);

    hResult = pRs->AddNew(vtMissing, vtMissing);

    set all fields ...

    hResult = pRs->Update();

    //* reconnect
    hResult = pRs->putref_ActiveConnection(m_spConnDispPtr);

    //*
    hResult = pRs->UpdateBatch(adAffectAll);
    hResult = pRs->Close();

2) How can you create a recordset from scratch without a connection
   and then connect to a database and Update() a table as long as
   all the field definitions are the same.

   The following is what I tried.  It didn't cause an error,
   but the database did not get updated.

   //* Open a recordset that is connected to the database
   //* so we can copy the filed definitions into the disconnected
   //* recordset.
   _RecordsetPtr   pRsDb("ADODB.Recordset");
   _RecordsetPtr   pRs("ADODB.Recordset");
   hRetVal = pRsDb->Open((variant_t)szTableName,
       m_spConnDispPtr, adOpenStatic, adLockReadOnly, adCmdTable);

    if (SUCCEEDED(hRetVal))
    {
        FieldsPtr   pFields = pRsDb->Fields;
        FieldPtr    pField = NULL;
        variant_t   vtIndex;

        //* Loop through each field, appending a copy to the
        //*  output recordset.
        for (INT i = 0; (i < pFields->Count) && (SUCCEEDED(hRetVal));
i++)
        {
            vtIndex = (LONG)i;
            pField = pFields->Item[vtIndex];
            hRetVal = pRs->Fields->Append(pField->Name, pField->Type,
                      pField->DefinedSize,
                       (FieldAttribu{*word*249}um)pField->Attributes );
        }
    }

    //* Open the disconnected recordset.
    pRs->CursorLocation = adUseClient;
    hRetVal = pRs->Open(bstrEmpty, vtMissing, adOpenKeyset,
        adLockOptimistic, adCmdUnknown);

    hResult = pRs->AddNew(vtMissing, vtMissing);

    ... set all fields

    hResult = pRs->Update();

    //* connect to the database and update
    hResult = pRs->putref_ActiveConnection(m_spConnDispPtr);
    hResult = pRs->UpdateBatch(adAffectAll);
    hResult = pRs->Close();

I guess my question here is how to you set the table name that is
to be affected?

And what else am I doing wrong?

I'm fairly new to ADO, so I appologize if this question is a
no-brainer for most of you.

any help would be appreciated

Thanks,
    noirracoon.

Sent via Deja.com http://www.deja.com/
Before you buy.