Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. ADO To MS Access Database.

ADO To MS Access Database.

Scheduled Pinned Locked Moved Database
helpdatabasecomquestion
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Mike Certini
    wrote on last edited by
    #1

    I am having problems with executing a command object in ADO. The specific problem I have revolves around the proper type for the SQL string. Following examples on the internet, I established it with a _bstr_t. This though is not working with the * VARIANT type that is required in the Execute method. Can someone help me with the proper establishment of the SQL string? Listed below is the complete program: Here is my error message coming out of the try block: error C2664: 'ADODB::Command15::Execute' : cannot convert parameter 1 from '_bstr_t' to 'VARIANT *' 1> No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called

    #include <stdio.h>
    #include <string>
    using std::string;

    int cyc = 0;

    #import "c:\program files\common files\system\ado\msado15.dll" rename ("EOF","EOFile")
    using namespace std;

    struct StartOLEProcess{
    StartOLEProcess( ) {
    ::CoInitialize(NULL);
    }
    ~StartOLEProcess( ) {
    ::CoUninitialize( );
    }
    } _start_StartOLEProcess;

    void main(void)
    {
    // define our variables which will be used as references to the
    // Connection and Recordset objects

    ADODB::\_ConnectionPtr  con = NULL;
    ADODB::\_RecordsetPtr   rec = NULL;
    ADODB::\_CommandPtr	   com = NULL;
    ADODB::\_ParameterPtr   par = NULL;
     
    // create two strings for use with the creation of a Connection
    // and a Recordset object
    
    bstr\_t                 sConString;
    bstr\_t                 sSQLString;
    
    // create a variable to hold the result to function calls
    
    HRESULT                hr                = S\_OK;
    
    // long variable needed for Execute method of Connection object
    
    VARIANT                \*vRecordsAffected = NULL;
    
    // create instance of an ADO Connection object, ADO Command object, ADO Parameter object, ADO Record object
    
    hr = con.CreateInstance(\_\_uuidof(ADODB::Connection));
    hr = com.CreateInstance(\_\_uuidof(ADODB::Command));
    hr = par.CreateInstance(\_\_uuidof(ADODB::Parameter));
    hr = rec.CreateInstance(\_\_uuidof(ADODB::Record));
    
    printf("Connection object created.\\n");
    
    // open the data source with the Connection object
    
    sConString = L"Provider=Microsoft.Jet.OLEDB.4.0;" 
                 L"Data Source=C:\\\\Users\\\\Mike Certini\\\\Documents\\\\Trading\\\\Databases\\\\TradingAnalysis#2.mdb";
    			 //L"DataSchema=mytable";
    
    // open the connection.
    
    hr = con->Open(sC
    
    W 1 Reply Last reply
    0
    • M Mike Certini

      I am having problems with executing a command object in ADO. The specific problem I have revolves around the proper type for the SQL string. Following examples on the internet, I established it with a _bstr_t. This though is not working with the * VARIANT type that is required in the Execute method. Can someone help me with the proper establishment of the SQL string? Listed below is the complete program: Here is my error message coming out of the try block: error C2664: 'ADODB::Command15::Execute' : cannot convert parameter 1 from '_bstr_t' to 'VARIANT *' 1> No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called

      #include <stdio.h>
      #include <string>
      using std::string;

      int cyc = 0;

      #import "c:\program files\common files\system\ado\msado15.dll" rename ("EOF","EOFile")
      using namespace std;

      struct StartOLEProcess{
      StartOLEProcess( ) {
      ::CoInitialize(NULL);
      }
      ~StartOLEProcess( ) {
      ::CoUninitialize( );
      }
      } _start_StartOLEProcess;

      void main(void)
      {
      // define our variables which will be used as references to the
      // Connection and Recordset objects

      ADODB::\_ConnectionPtr  con = NULL;
      ADODB::\_RecordsetPtr   rec = NULL;
      ADODB::\_CommandPtr	   com = NULL;
      ADODB::\_ParameterPtr   par = NULL;
       
      // create two strings for use with the creation of a Connection
      // and a Recordset object
      
      bstr\_t                 sConString;
      bstr\_t                 sSQLString;
      
      // create a variable to hold the result to function calls
      
      HRESULT                hr                = S\_OK;
      
      // long variable needed for Execute method of Connection object
      
      VARIANT                \*vRecordsAffected = NULL;
      
      // create instance of an ADO Connection object, ADO Command object, ADO Parameter object, ADO Record object
      
      hr = con.CreateInstance(\_\_uuidof(ADODB::Connection));
      hr = com.CreateInstance(\_\_uuidof(ADODB::Command));
      hr = par.CreateInstance(\_\_uuidof(ADODB::Parameter));
      hr = rec.CreateInstance(\_\_uuidof(ADODB::Record));
      
      printf("Connection object created.\\n");
      
      // open the data source with the Connection object
      
      sConString = L"Provider=Microsoft.Jet.OLEDB.4.0;" 
                   L"Data Source=C:\\\\Users\\\\Mike Certini\\\\Documents\\\\Trading\\\\Databases\\\\TradingAnalysis#2.mdb";
      			 //L"DataSchema=mytable";
      
      // open the connection.
      
      hr = con->Open(sC
      
      W Offline
      W Offline
      Wendelius
      wrote on last edited by
      #2

      Hi, Few observations: - your command type shouldn't be adCmdStoredProc since you're executing a normal DML statement. Use adCmdText instead. - the SQL statement for insert should contain the VALUES section and the parameters to use, like:

      _bstr_t strSQL("INSERT INTO mytable(id,desc) VALUES (?, ?)");

      - the execute contains the SQL statement as a parameter. I'm not sure if there's such overload, normally the first parameter is the number of records affected, see: http://msdn.microsoft.com/en-us/library/ms681559(VS.85).aspx[^]

      The need to optimize rises from a bad design.My articles[^]

      M 1 Reply Last reply
      0
      • W Wendelius

        Hi, Few observations: - your command type shouldn't be adCmdStoredProc since you're executing a normal DML statement. Use adCmdText instead. - the SQL statement for insert should contain the VALUES section and the parameters to use, like:

        _bstr_t strSQL("INSERT INTO mytable(id,desc) VALUES (?, ?)");

        - the execute contains the SQL statement as a parameter. I'm not sure if there's such overload, normally the first parameter is the number of records affected, see: http://msdn.microsoft.com/en-us/library/ms681559(VS.85).aspx[^]

        The need to optimize rises from a bad design.My articles[^]

        M Offline
        M Offline
        Mike Certini
        wrote on last edited by
        #3

        Mika, Thank you for your response. After making the changes you suggested I get the following error. Instead of the "Records Affected" parameter, I have input "NULL". As a result, I am getting this error: Connection object created. Connection has been opened. Error Code = 80040e14 Code meaning = I Source = Microsoft JET Database Engine Description = Expected query name after EXECUTE.

        W 1 Reply Last reply
        0
        • M Mike Certini

          Mika, Thank you for your response. After making the changes you suggested I get the following error. Instead of the "Records Affected" parameter, I have input "NULL". As a result, I am getting this error: Connection object created. Connection has been opened. Error Code = 80040e14 Code meaning = I Source = Microsoft JET Database Engine Description = Expected query name after EXECUTE.

          W Offline
          W Offline
          Wendelius
          wrote on last edited by
          #4

          Hi, Could be some kind of syntax issue in the SQL statement itself. Also if I rememeber correctly the parameter usage in the sql statement may be provider specific so if the SQL statement is otherwise fine could it be because of the question mark. You could try literals as a test n order to see if that's the case. Also perhaps the following link would help you: http://msdn.microsoft.com/en-us/library/ms677554(v=VS.85).aspx[^]

          The need to optimize rises from a bad design.My articles[^]

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups