Search code examples
c++windows-cevariantlong-long

How can I convert from LONGLONG to class _variant_t?


In this example m_Amount is CString. stringToNumber function converts it to a LONGLONG number successfully. But when I want to assign it to a variant I get this error:

error C2440: 'type cast' : cannot convert from '__int64' to 'class _variant_t'

mycode

_variant_t  myVar = _variant_t( (LONGLONG)stringToNumber(m_Amount) );

Solution

  • I was using _variant_t to insert LONGLONG data into the SQL server database. As mentioned in this asnwer numeric is mapped to CString in C++. So I retrieve my numeric data from database as string, convert it to LONGLONG, change and then convert it to string again and store result string to database.

    SQL numeric --(retrieve from database)--> string -> LONGLONG -> string --(insert into the database)--> SQL numeric