ADO Field Append and creating a disconnected recordset 
Author Message
 ADO Field Append and creating a disconnected recordset

Here's the story...

I have a method that returns a _Recordset **pRs.

If I run into any errors in the method, I want to create an 'Error'
recordset that contains the error info. I know how to do this in VB with
Fields.Append and such.

While trying to do it in VC++ I am crashing. What is the correct way to do
this?

// Code snippet //

HRESULT         hr;
_RecordsetPtr    pRS;

hr = pRS.CreateInstance(__uuidof(Recordset);

pRS->CursorLocation = adUseClient;
pRS->CursorType = adOpenDynamic;
pRS->LockType = adLockBatchOptimistic;

// Open the disconnected recordset
//
// Fails with error!!!!!
//
pRS->Open("", "", adOpenDynamic, adLockBatchOptimistic, adCmdText);

// Set up the recordset to hold the error info
pRS->Fields->Append(_T("ErrorCondition"), adVarChar, 256, adFldUpdatable);
pRS->Fields->Append(_T("Number"), adInteger, 4, adFldUpdatable);
pRS->Fields->Append(_T("Source"), adVarChar, 256, adFldUpdatable);

...
etc...
...



Mon, 11 Feb 2002 03:00:00 GMT
 ADO Field Append and creating a disconnected recordset

Hi Dan,

According to the Wrox book: "Pro ADO RDS Progamming",
you can should call the Open method AFTER defining the fields, e.g.
(see page 182)

..
 // Set up the recordset to hold the error info
 pRS->Fields->Append(_T("ErrorCondition"), adVarChar, 256, adFldUpdatable);
 pRS->Fields->Append(_T("Number"), adInteger, 4, adFldUpdatable);
 pRS->Fields->Append(_T("Source"), adVarChar, 256, adFldUpdatable);

pRS->Open("", "", adOpenDynamic, adLockBatchOptimistic, adCmdText);
 ..

Also, the book calls this a "Custom" recordset, instead of a Disconnected
one.

The bad news is that I have tried this, but ADO complained about
data source or provider not found.

Please let me know if you find the solution,
tom.


Quote:
> Here's the story...

> I have a method that returns a _Recordset **pRs.

> If I run into any errors in the method, I want to create an 'Error'
> recordset that contains the error info. I know how to do this in VB with
> Fields.Append and such.

> While trying to do it in VC++ I am crashing. What is the correct way to do
> this?

> // Code snippet //

> HRESULT         hr;
> _RecordsetPtr    pRS;

> hr = pRS.CreateInstance(__uuidof(Recordset);

> pRS->CursorLocation = adUseClient;
> pRS->CursorType = adOpenDynamic;
> pRS->LockType = adLockBatchOptimistic;

> // Open the disconnected recordset
> //
> // Fails with error!!!!!
> //
> pRS->Open("", "", adOpenDynamic, adLockBatchOptimistic, adCmdText);

> // Set up the recordset to hold the error info
> pRS->Fields->Append(_T("ErrorCondition"), adVarChar, 256, adFldUpdatable);
> pRS->Fields->Append(_T("Number"), adInteger, 4, adFldUpdatable);
> pRS->Fields->Append(_T("Source"), adVarChar, 256, adFldUpdatable);

> ...
> etc...
> ...



Mon, 25 Feb 2002 03:00:00 GMT
 ADO Field Append and creating a disconnected recordset
Hi Thanh,

I believe that a problem with your code is in the second parameter of the Open()
function - it can not be just an empty string. Use a properly initialized
_variant_t variable instead. Here is the code that works:

 //HOWTO: Create and use custom recordset
 _variant_t vNull;
 vNull.vt=VT_ERROR;
 vNull.scode=DISP_E_PARAMNOTFOUND;

 _RecordsetPtr rsTmp3;
 rsTmp3.CreateInstance(__uuidof(Recordset));
 rsTmp3->Fields->Append("FName", adInteger, 4, adFldUnspecified);
 rsTmp3->Open(_variant_t(_bstr_t(L"")), vNull, adOpenStatic, adLockOptimistic,
adCmdText);
 rsTmp3->AddNew();
 rsTmp3->Update(L"FName", &(_variant_t((short) 5)));
 //etc.

Regards,

Quote:

> Hi Dan,

> According to the Wrox book: "Pro ADO RDS Progamming",
> you can should call the Open method AFTER defining the fields, e.g.
> (see page 182)

> ..
>  // Set up the recordset to hold the error info
>  pRS->Fields->Append(_T("ErrorCondition"), adVarChar, 256, adFldUpdatable);
>  pRS->Fields->Append(_T("Number"), adInteger, 4, adFldUpdatable);
>  pRS->Fields->Append(_T("Source"), adVarChar, 256, adFldUpdatable);

> pRS->Open("", "", adOpenDynamic, adLockBatchOptimistic, adCmdText);
>  ..

> Also, the book calls this a "Custom" recordset, instead of a Disconnected
> one.

> The bad news is that I have tried this, but ADO complained about
> data source or provider not found.

> Please let me know if you find the solution,
> tom.



> > Here's the story...

> > I have a method that returns a _Recordset **pRs.

> > If I run into any errors in the method, I want to create an 'Error'
> > recordset that contains the error info. I know how to do this in VB with
> > Fields.Append and such.

> > While trying to do it in VC++ I am crashing. What is the correct way to do
> > this?

> > // Code snippet //

> > HRESULT         hr;
> > _RecordsetPtr    pRS;

> > hr = pRS.CreateInstance(__uuidof(Recordset);

> > pRS->CursorLocation = adUseClient;
> > pRS->CursorType = adOpenDynamic;
> > pRS->LockType = adLockBatchOptimistic;

> > // Open the disconnected recordset
> > //
> > // Fails with error!!!!!
> > //
> > pRS->Open("", "", adOpenDynamic, adLockBatchOptimistic, adCmdText);

> > // Set up the recordset to hold the error info
> > pRS->Fields->Append(_T("ErrorCondition"), adVarChar, 256, adFldUpdatable);
> > pRS->Fields->Append(_T("Number"), adInteger, 4, adFldUpdatable);
> > pRS->Fields->Append(_T("Source"), adVarChar, 256, adFldUpdatable);

> > ...
> > etc...
> > ...



Mon, 25 Feb 2002 03:00:00 GMT
 ADO Field Append and creating a disconnected recordset
I am having the same problem using the open command in C++.  I have found
that in VB the following example works...

Dim rs AS ADOR.Recordset
rs.Fields.Append "ErrorCondition", adVarChar, 256, adFldUpdatable
rs.Fields.Append "Number", adInteger, 4, adFldUpdatable
rs.Fields.Append "Source", adVarChar, 256, adFldUpdatable
rs.Open

But if you call
    rs.Open "", "" or
    rs.Open 0,0 or even
    rs.Open Empty, Empty
instead of
    rs.Open
the method fails in the same manner as the C++ open call fails.  The last
three parameters, OpenType, LockType, and CmdType, seem to have no effect on
the error/no error outcome.

However, I do not wish to cripple the rest of my business object by writing
it in VB.  The problem seems to be that we need to be able to not pass
anything to the open method for the Source and Connection parameters the
same way that VB does.  Some alternatives spring to mind.

1) Use IDispatch to make the call and don't pass any parameters. ( I believe
this is how VB does it )
2) Create a VB object that creates the recordset, opens it and returns the
interface pointer to it.

But neither of these really seems like a clean solution.  I would definitely
prefer to make the call in C++ via the defined interface, but I have run out
of ideas on how to do so. I would appreciate any help in this manner.

Additionally, this is in fact a custom recordset, although technically
speaking it is also a disconnected recordset.  You can use disconnected
recordsets that are not custom recordsets. Disconnected recordset are
created buy opening a recordset of a query, table, command, custom
recordset, saved recordset file, etc..., then setting the active connection
to NULL( pRS->PutRefActiveConnection(NULL) ).

Jason Skidis


Quote:
> Hi Dan,

> According to the Wrox book: "Pro ADO RDS Progamming",
> you can should call the Open method AFTER defining the fields, e.g.
> (see page 182)

> ..
>  // Set up the recordset to hold the error info
>  pRS->Fields->Append(_T("ErrorCondition"), adVarChar, 256,
adFldUpdatable);
>  pRS->Fields->Append(_T("Number"), adInteger, 4, adFldUpdatable);
>  pRS->Fields->Append(_T("Source"), adVarChar, 256, adFldUpdatable);

> pRS->Open("", "", adOpenDynamic, adLockBatchOptimistic, adCmdText);
>  ..

> Also, the book calls this a "Custom" recordset, instead of a Disconnected
> one.

> The bad news is that I have tried this, but ADO complained about
> data source or provider not found.



> > HRESULT         hr;
> > _RecordsetPtr    pRS;

> > hr = pRS.CreateInstance(__uuidof(Recordset);

> > pRS->CursorLocation = adUseClient;
> > pRS->CursorType = adOpenDynamic;
> > pRS->LockType = adLockBatchOptimistic;

> > // Open the disconnected recordset
> > //
> > // Fails with error!!!!!
> > //
> > pRS->Open("", "", adOpenDynamic, adLockBatchOptimistic, adCmdText);

> > // Set up the recordset to hold the error info
> > pRS->Fields->Append(_T("ErrorCondition"), adVarChar, 256,
adFldUpdatable);
> > pRS->Fields->Append(_T("Number"), adInteger, 4, adFldUpdatable);
> > pRS->Fields->Append(_T("Source"), adVarChar, 256, adFldUpdatable);

> > ...
> > etc...
> > ...



Fri, 22 Mar 2002 03:00:00 GMT
 ADO Field Append and creating a disconnected recordset
There is a third option.

 // Set up the recordset to hold the error info
pRS->Fields->Append(_T("ErrorCondition"), adVarChar, 256,
adFldUpdatable);
pRS->Fields->Append(_T("Number"), adInteger, 4, adFldUpdatable);
pRS->Fields->Append(_T("Source"), adVarChar, 256, adFldUpdatable);

pRS->Open(vtMissing, vtMissing, adOpenUnspecified, adOpenUnspecified,
adCmdUnspecified);


Quote:
> in VB the following example works...

> Dim rs AS ADOR.Recordset
> rs.Fields.Append "ErrorCondition", adVarChar, 256, adFldUpdatable
> rs.Fields.Append "Number", adInteger, 4, adFldUpdatable
> rs.Fields.Append "Source", adVarChar, 256, adFldUpdatable
> rs.Open

> But if you call
>     rs.Open "", "" or
>     rs.Open 0,0 or even
>     rs.Open Empty, Empty
> instead of
>     rs.Open
> the method fails in the same manner as the C++ open call fails.  The last
> three parameters, OpenType, LockType, and CmdType, seem to have no effect
on
> the error/no error outcome.

> However, I do not wish to cripple the rest of my business object by
writing
> it in VB.  The problem seems to be that we need to be able to not pass
> anything to the open method for the Source and Connection parameters the
> same way that VB does.  Some alternatives spring to mind.

> 1) Use IDispatch to make the call and don't pass any parameters. ( I
believe
> this is how VB does it )
> 2) Create a VB object that creates the recordset, opens it and returns the
> interface pointer to it.



> >  According to the Wrox book: "Pro ADO RDS Progamming",
> >  you can should call the Open method AFTER defining the fields, e.g.
> >  (see page 182)

> >  // Set up the recordset to hold the error info
> >  pRS->Fields->Append(_T("ErrorCondition"), adVarChar, 256,
> adFldUpdatable);
> >  pRS->Fields->Append(_T("Number"), adInteger, 4, adFldUpdatable);
> >  pRS->Fields->Append(_T("Source"), adVarChar, 256, adFldUpdatable);

> > pRS->Open("", "", adOpenDynamic, adLockBatchOptimistic, adCmdText);
> >  ..
> > The bad news is that I have tried this, but ADO complained about
> > data source or provider not found.



> > > HRESULT         hr;
> > > _RecordsetPtr    pRS;

> > > hr = pRS.CreateInstance(__uuidof(Recordset);

> > > pRS->CursorLocation = adUseClient;
> > > pRS->CursorType = adOpenDynamic;
> > > pRS->LockType = adLockBatchOptimistic;

> > > // Open the disconnected recordset
> > > //
> > > // Fails with error!!!!!
> > > //
> > > pRS->Open("", "", adOpenDynamic, adLockBatchOptimistic, adCmdText);

> > > // Set up the recordset to hold the error info
> > > pRS->Fields->Append(_T("ErrorCondition"), adVarChar, 256,
> adFldUpdatable);
> > > pRS->Fields->Append(_T("Number"), adInteger, 4, adFldUpdatable);
> > > pRS->Fields->Append(_T("Source"), adVarChar, 256, adFldUpdatable);



Fri, 22 Mar 2002 03:00:00 GMT
 ADO Field Append and creating a disconnected recordset

Quote:


> > Hi Dan,

> > According to the Wrox book: "Pro ADO RDS Progamming",
> > you can should call the Open method AFTER defining the fields, e.g.
> > (see page 182)

> > ..
> >  // Set up the recordset to hold the error info
> >  pRS->Fields->Append(_T("ErrorCondition"), adVarChar, 256,
> adFldUpdatable);
> >  pRS->Fields->Append(_T("Number"), adInteger, 4, adFldUpdatable);
> >  pRS->Fields->Append(_T("Source"), adVarChar, 256, adFldUpdatable);

> > pRS->Open("", "", adOpenDynamic, adLockBatchOptimistic, adCmdText);
> >  ..

> > Also, the book calls this a "Custom" recordset, instead of a
Disconnected
> > one.

> > The bad news is that I have tried this, but ADO complained about
> > data source or provider not found.




What I found today, is that to open a disconnected ADO recordset in C++
you call it this way:

rs->Open ( vtMissing, vtMissing, adOpenDynamic, adLockBatchOptimistic,
adCmdText );

vtMissing is the answer. Not an empty string or a null viariant. Just
plain vtMissing.

Cezar

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



Tue, 26 Mar 2002 03:00:00 GMT
 
 [ 6 post ] 

 Relevant Pages 

1. Appending fields on a disconnected recordset

2. Append Field with Disconnected Recordset, Please Help!

3. Disconnected Recordsets (appending fields)

4. Creating disconnected ADO recordsets

5. Creating disconnected ADO recordset

6. Creating disconnected ADO recordsets

7. Create an dpopulate a disconnected copy of an ADO Recordset generated from Oracle (MSDAORA)

8. Create and append an ADO Recordset in VC++

9. create autonumber field in a disconnected recordset?

10. create autonumber field in a disconnected recordset?

11. Appending fields to an existing persistent ADO recordset?

12. How to append fields to existing perisistent ADO recordsets


 
Powered by phpBB® Forum Software