Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. converting _variant_t to string

converting _variant_t to string

Scheduled Pinned Locked Moved C / C++ / MFC
c++databasetutorialquestion
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    Lost User
    wrote on last edited by
    #1

    Hi there, I am using the ADO calls to connect to my database and have the following call: _variant_t varFieldValue; varFieldValue = m_pRecord->Fields->GetItem((long)nCol)->GetValue(); Now, at some point , I like to convert this varFieldValue to a string, preferably a STL string. Any tips on how to do this? thanks

    N 1 Reply Last reply
    0
    • L Lost User

      Hi there, I am using the ADO calls to connect to my database and have the following call: _variant_t varFieldValue; varFieldValue = m_pRecord->Fields->GetItem((long)nCol)->GetValue(); Now, at some point , I like to convert this varFieldValue to a string, preferably a STL string. Any tips on how to do this? thanks

      N Offline
      N Offline
      NapiSpooler
      wrote on last edited by
      #2

      this should get your variant value into a CString. CString strTest; strTest = varFieldValue.bstrVal;

      T 1 Reply Last reply
      0
      • N NapiSpooler

        this should get your variant value into a CString. CString strTest; strTest = varFieldValue.bstrVal;

        T Offline
        T Offline
        Tim Smith
        wrote on last edited by
        #3

        Nope, that won't work if the variant isn't already a VT_BSTR. However using static_cast <_bstr_t> (v) will convert the variant to a BSTR and return the string. Tim Smith I know what you're thinking punk, you're thinking did he spell check this document? Well, to tell you the truth I kinda forgot myself in all this excitement. But being this here's CodeProject, the most powerful forums in the world and would blow your head clean off, you've got to ask yourself one question, Do I feel lucky? Well do ya punk?

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups