Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

MSVC++ 6 /ADO /Access  /variant class

Posted on 2002-03-04
2
Medium Priority
?
301 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 200 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

730 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