Click here to Skip to main content
15,892,072 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hello all,

I have written a code in VC++ 6.0,which fires a query to database against ADODB connection & feteches a int data in _variant_t var object.
C++
_variant_t var;
var = recordset->Fields->GetItem(L"id")->GetValue();

Now, I want to store this "id" value in a long array.For this I need to convert the value in var to long.
I tried storing var.lVal in the array but dint worked. Another option I can see is to convert var to char* & then use atol() to convert to long.

How to achieve either of the conversion (i.e. to long or to char*)?

Thanks.
Posted
Updated 10-Aug-10 4:19am
v2

1 solution

Either look at the type (the vt field), and then read the relevant field in the underlying VARIANT structure, or use one of the accessor functions[^].

Since the accessors may call VariantChangeType, you may not get the results you expect. Looking at the vt field is the more robust way to go.
 
Share this answer
 
Comments
Nish Nishant 10-Aug-10 12:10pm    
Reason for my vote of 5
Proposed answer.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900