What is GetCollect? 
Author Message
 What is GetCollect?

The book I bought to learn database programming in VC++
was "Teach Yourself Database programming with Visual C++ 6
is 21 Days", from SAMS.

In it, the author is fairly consistent in the way he gets
data out of records.

_RecordsetPtr pRS;
_variant_t v;

v=pRS->GetCollect(L"fieldname");

But what is GetCollect()?  It works beautifully, but it
isn't referenced anywhere in the MSDN library or any other
source I can find.  The problem is that if I want to pass
the argument to GetCollect as a variable, I don't know
what sort of variable to pass it.  

ie. CString csfieldname;
csfieldname="fieldname";

GetCollect(csfieldname.GetBuffer(0));//doesn't work.

What is that variable?  The one where L"fieldname always
works, but none of the other variations I can think of
work.

Or..alternatively.. I want a function which, given a
recordset and a field name will return a variant that
contains the value of the field with that field name.  I
use GetCollect for that purpose, but I'm beginning to
wonder if that is really what I ought to be using.



Tue, 26 Apr 2005 23:58:23 GMT
 What is GetCollect?

David,

GetCollect is missing from all of the ADO documentation - but it is NOT
**undocumented** in the classic sense - in other works, it is perfectly
correct to use it..   The reason for the lack of documentation is that the
**MAJORITY** of the documentation is written to the VB or VBScript audience.
GetCollect and its counterpart, PutCollect are helper methods of the
Recordset class -- they are in the vtable, but not in the automation methods
list.  Remember - ADO exposes a dual interface - IDispatch, and then all of
the methods of the class.

GetCollect is a but a shortcut method that operates directly on the Fields
collection in the Recordset.  Hence, these two are equivalent, but the
GetCollect is more efficient:
1)  _bstr_t fname = rset->Fields->GetItem((short)0).Value;
2)  _bstr_t fname = rset->GetCollect((short)0).Value;

GetCollect takes one argument - it is a variant, and it identifies the field
that you are "GET-ing" You can pass the field name, or pass a ordinal
value - but the type of the variable ultimately VARIANT.  The arguments are
defined as _variant_t, and if you look in MSDN, you will find there are a
lot of c-tors for the _variant_t class, so specifying an int will cause the
compiler to insert a c-tor/conversion as appropriate.   So either of these
will work, given the following sql statement:
"Select fname,lname from names"

1)  _bstr_t fname = rset->Fields->GetItem((short)0).Value;
2)  _bstr_t fname = rset->Fields->GetItem(L"FNAME").Value;
3)  _bstr_t fname = rset->GetCollect((short)0).Value;
4)  _bstr_t fname = rset->GetCollect(L"FNAME").Value;
5) BSTR fname =  ::SysAllocString(rset->GetCollect((short)0).Value.bstrVal);

The counterpart PutCollect takes two arguments - the field name or ordinal
and the VARIANT value.  Both parameters are passed in the helper _variant_t
class.

I hope this helps...

regards
roy fine


Quote:
> The book I bought to learn database programming in VC++
> was "Teach Yourself Database programming with Visual C++ 6
> is 21 Days", from SAMS.

> In it, the author is fairly consistent in the way he gets
> data out of records.

> _RecordsetPtr pRS;
> _variant_t v;

> v=pRS->GetCollect(L"fieldname");

> But what is GetCollect()?  It works beautifully, but it
> isn't referenced anywhere in the MSDN library or any other
> source I can find.  The problem is that if I want to pass
> the argument to GetCollect as a variable, I don't know
> what sort of variable to pass it.

> ie. CString csfieldname;
> csfieldname="fieldname";

> GetCollect(csfieldname.GetBuffer(0));//doesn't work.

> What is that variable?  The one where L"fieldname always
> works, but none of the other variations I can think of
> work.

> Or..alternatively.. I want a function which, given a
> recordset and a field name will return a variant that
> contains the value of the field with that field name.  I
> use GetCollect for that purpose, but I'm beginning to
> wonder if that is really what I ought to be using.



Wed, 27 Apr 2005 09:29:28 GMT
 What is GetCollect?
Many thanks
Quote:
>-----Original Message-----
>David,

>GetCollect is missing from all of the ADO documentation -
but it is NOT
>**undocumented** in the classic sense - in other works,
it is perfectly
>correct to use it..   The reason for the lack of

documentation is that the
Quote:
>**MAJORITY** of the documentation is written to the VB or
VBScript audience.
>GetCollect and its counterpart, PutCollect are helper
methods of the
>Recordset class -- they are in the vtable, but not in the
automation methods
>list.  Remember - ADO exposes a dual interface -

IDispatch, and then all of
Quote:
>the methods of the class.

>GetCollect is a but a shortcut method that operates

directly on the Fields
Quote:
>collection in the Recordset.  Hence, these two are
equivalent, but the
>GetCollect is more efficient:
>1)  _bstr_t fname = rset->Fields->GetItem((short)0).Value;
>2)  _bstr_t fname = rset->GetCollect((short)0).Value;

>GetCollect takes one argument - it is a variant, and it

identifies the field
Quote:
>that you are "GET-ing" You can pass the field name, or
pass a ordinal
>value - but the type of the variable ultimately VARIANT.  
The arguments are
>defined as _variant_t, and if you look in MSDN, you will
find there are a
>lot of c-tors for the _variant_t class, so specifying an
int will cause the
>compiler to insert a c-tor/conversion as appropriate.  
So either of these
>will work, given the following sql statement:
>"Select fname,lname from names"

>1)  _bstr_t fname = rset->Fields->GetItem((short)0).Value;
>2)  _bstr_t fname = rset->Fields->GetItem(L"FNAME").Value;
>3)  _bstr_t fname = rset->GetCollect((short)0).Value;
>4)  _bstr_t fname = rset->GetCollect(L"FNAME").Value;
>5) BSTR fname =  ::SysAllocString(rset->GetCollect((short)
0).Value.bstrVal);

>The counterpart PutCollect takes two arguments - the

field name or ordinal

- Show quoted text -

Quote:
>and the VARIANT value.  Both parameters are passed in the
helper _variant_t
>class.

>I hope this helps...

>regards
>roy fine



>> The book I bought to learn database programming in VC++
>> was "Teach Yourself Database programming with Visual
C++ 6
>> is 21 Days", from SAMS.

>> In it, the author is fairly consistent in the way he
gets
>> data out of records.

>> _RecordsetPtr pRS;
>> _variant_t v;

>> v=pRS->GetCollect(L"fieldname");

>> But what is GetCollect()?  It works beautifully, but it
>> isn't referenced anywhere in the MSDN library or any
other
>> source I can find.  The problem is that if I want to
pass
>> the argument to GetCollect as a variable, I don't know
>> what sort of variable to pass it.

>> ie. CString csfieldname;
>> csfieldname="fieldname";

>> GetCollect(csfieldname.GetBuffer(0));//doesn't work.

>> What is that variable?  The one where L"fieldname always
>> works, but none of the other variations I can think of
>> work.

>> Or..alternatively.. I want a function which, given a
>> recordset and a field name will return a variant that
>> contains the value of the field with that field name.  I
>> use GetCollect for that purpose, but I'm beginning to
>> wonder if that is really what I ought to be using.

>.



Sat, 30 Apr 2005 00:28:07 GMT
 
 [ 3 post ] 

 Relevant Pages 

1. _RecordsetPtr::GetCollect(), PutCollect() question

2. ADO and GetCollect

3. GetCollect problem

4. GetCollect type

5. GetCollect and Null data

6. I am getting this message when i am tring to export or import anything using

7. error ORA-01855: AM/A.M. or PM/P.M. required

8. Busy Day = Slowdown from 12 AM - 5 AM

9. Use of @am, Am I dumb?

10. I am a pain in the butt, however I am learning !

11. Hi, I am stuck.When I submit the form, I am not sure what exactly have been submitted.

12. Am installing a store on NT4 and SQL7sp1 and am getting this message...when trying to access..


 
Powered by phpBB® Forum Software