Solved

MSVC++ 6 /ADO /Access  /variant class

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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

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

Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
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 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 clear a vector as well as how to detect empty vectors in C++.

860 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