Thread View: microsoft.public.data.ado
1 messages
1 total messages
Started by noirracoon
Fri, 07 Jul 2000 00:00
Updating db by connecting a disconnected recordset in ADO
Author: noirracoon
Date: Fri, 07 Jul 2000 00:00
Date: Fri, 07 Jul 2000 00:00
99 lines
3747 bytes
3747 bytes
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,
(FieldAttributeEnum)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.
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads