Solved

MSVC++ 6 /ADO /Access  /variant class

Posted on 2002-03-04
2
293 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
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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
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…

815 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

9 Experts available now in Live!

Get 1:1 Help Now