Solved

MSVC++ 6 /ADO /Access  /variant class

Posted on 2002-03-04
2
284 Views
Last Modified: 2008-02-01
I am trying to put data into an MDB using variant
class. Strings are going in as "Hello", integers
are going into number type as "1" . I want to put
a value into Access datatype yes/no , but I have
failed trying "1" , "yes" and "TRUE" for yes.
What does Access need to see ????
In code below only the commented Boolean data will
not go into MDB correctly.
////////////
void Field::persist(CBTBXDoc* pBTBXDoc){
      AdoNS::_RecordsetPtr pRecordSet;
      
      HRESULT hr;
      _bstr_t bstrQuery("SELECT * FROM Field WHERE ID IS NULL");
      _variant_t vNull;      
      vNull.vt = VT_ERROR;
      vNull.scode = DISP_E_PARAMNOTFOUND;

      try
      {
            hr = pRecordSet.CreateInstance(_uuidof(AdoNS::Recordset));
            if (SUCCEEDED(hr))
            {
                  pRecordSet->PutRefActiveConnection(pBTBXDoc->m_pConnection);
                  hr = pRecordSet->Open(_variant_t(bstrQuery), vNull,
                        AdoNS::adOpenForwardOnly, AdoNS::adLockOptimistic, AdoNS::adCmdText);
                  if (SUCCEEDED(hr))
                  {
                        // Create an array for the list of fields in
                        // the Products table.
                        COleSafeArray vaFieldlist;
                        vaFieldlist.CreateOneDim(VT_VARIANT,7);
                        // Fill in the field names now.
                        long lArrayIndex[1];
                        lArrayIndex[0] = 0;
                        vaFieldlist.PutElement(lArrayIndex,
                              &(_variant_t("ID")));
                        lArrayIndex[0] = 1;
                        vaFieldlist.PutElement(lArrayIndex,
                              &(_variant_t("Name")));
                        lArrayIndex[0] = 2;
                        vaFieldlist.PutElement(lArrayIndex,
                              &(_variant_t("Tag")));
                        lArrayIndex[0] = 3;
                        vaFieldlist.PutElement(lArrayIndex,
                              &(_variant_t("BlockID")));
                  

                        lArrayIndex[0] = 4;
                        vaFieldlist.PutElement(lArrayIndex,
                              &(_variant_t("TypeDefID")));

                              lArrayIndex[0] = 5;
                        vaFieldlist.PutElement(lArrayIndex,
                              &(_variant_t("Attribs")));
                        lArrayIndex[0] = 6;
                        vaFieldlist.PutElement(lArrayIndex,
                              &(_variant_t("Path")));
/*
                                                lArrayIndex[0] = 7;
                        vaFieldlist.PutElement(lArrayIndex,
                              &(_variant_t("bLangDescID")));
*/
                        // Create an array for the list of values to go in
                        // the Products table.
                        COleSafeArray vaValuelist;
                        vaValuelist.CreateOneDim(VT_VARIANT,7);
                        // Fill in the values for each field.                        
                        stringstream ss;
                        lArrayIndex[0] = 0;
                        ss << _nID ;
                        vaValuelist.PutElement(lArrayIndex,
                              &(_variant_t((ss.str()).c_str())));// ID 1

                        lArrayIndex[0] = 1;
                        vaValuelist.PutElement(lArrayIndex,
                              &(_variant_t(_sName.c_str())));      //NAME 2

                        lArrayIndex[0] = 2;
                        vaValuelist.PutElement(lArrayIndex,
                              &(_variant_t(_sTag.c_str()))); //TAG 3

                        lArrayIndex[0] = 3;
                        ss.rdbuf()->pubseekoff(0,ios::beg,ios::out); // reset write ptr to beg
                        ss << (*_pBlock)._nID ;
string s = ss.str();
                        vaValuelist.PutElement(lArrayIndex,
                              &(_variant_t((ss.str()).c_str())));// BlockID 4

                        lArrayIndex[0] = 4;
                        ss.rdbuf()->pubseekoff(0,ios::beg,ios::out); // reset write ptr to beg
                        ss << (*_pTypeDef)._nID ;
                        vaValuelist.PutElement(lArrayIndex,
                              &(_variant_t((ss.str()).c_str())));      // TDefID 6

                        lArrayIndex[0] = 5;      
                        s = " ";
                        if(      ((*_pTypeDef)._plFieldAttrib) ){
                              for(list<string>::iterator sit =
                                    (*((*_pTypeDef)._plFieldAttrib)).begin();                              
                                          sit != (*((*_pTypeDef)._plFieldAttrib)).end(); sit++){
                                    s += *sit;
                                    list<string>::iterator sit2 = sit;
                                    if(++sit2 != (*((*_pTypeDef)._plFieldAttrib)).end())
                                          s += ", ";
                              }
                        }
                        vaValuelist.PutElement(lArrayIndex,
                              &(_variant_t(s.c_str())));      // sAttrib 7

                        lArrayIndex[0] = 6;                        
                        vaValuelist.PutElement(lArrayIndex,                         
                              &(_variant_t((*_pBlock)._sBlockPath.c_str())));      // Path 8
/**
                        lArrayIndex[0] = 7;                  
                        if(_plpLidDesc)                                    
                              vaValuelist.PutElement(lArrayIndex,
                                    &(_variant_t("TRUE")));// bLangDesc
                        else
                              vaValuelist.PutElement(lArrayIndex,
                                    &(_variant_t("FALSE")));// bLangDesc 5
**/
                        pRecordSet->AddNew(vaFieldlist, vaValuelist);
                  
                        pRecordSet->Close();
                  }
            }
            for(list<Fel*>::iterator itF = FlFel.begin();itF != FlFel.end();itF++){
                  string id = (**itF).id();
                  (**itF).persist(pBTBXDoc) ; //recurse
            }
      }
    catch( _com_error &e )
    {
            TRACE( "Error:%08lx.\n", e.Error());
            TRACE( "ErrorMessage:%s.\n", e.ErrorMessage());
            TRACE( "Source:%s.\n", (LPCTSTR) _bstr_t(e.Source()));
            TRACE( "Description:%s.\n", (LPCTSTR) _bstr_t(e.Description()));
    }
    catch(...)
    {
      TRACE( "\n*** Unhandled Exception ***\n" );
    }
      

}
0
Comment
Question by:mebarron
2 Comments
 

Accepted Solution

by:
eagleyin earned 50 total points
Comment Utility
Well, just read the "yes/no" data from an already existing record( maybe you can input that record in Access ) and try to see what it is.
0
 

Author Comment

by:mebarron
Comment Utility
good answer
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now