Solved

MSVC++ 6 /ADO /Access  /variant class

Posted on 2002-03-04
2
296 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 

Accepted Solution

by:
eagleyin earned 50 total points
ID: 6840921
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
ID: 6841426
good answer
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

756 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