title: Fastest way to add multiple records to ADO recordset using C++
body: <p>We have a data model that supports single table databases hosted on multiple servers. However we occasionally need to compile data from multiple tables for display on classic ASP pages. This is done in a COM object in C++. We gather the data from SQL Server using OleDb, with the OleDb logic writing the data straight into C++ structs. We then loop through the struct arrays adding the data to SafeArrays, then add these to the recordset. The logic to add the data to the recordset looks roughly like the following (initialisation and error handling logic omitted):</p>
  
  <pre><code>SAFEARRAY* fields; // Initialised to integer array 0 -&gt; max fields
  SAFEARRAY* values;
  VARIANT* arraydata;
  
  ... //  initialisation logic
  
  SafeArrayAccessData(values, reinterpret_cast&lt;void**&gt;(&amp;arrayData));
  
  for(unsigned int i = 0; i &lt; numDataValues1; ++i)
  {
      // Add data
      arraydata[0].intVal = data[i].someValue;
      ... // etc.
  
      for(unsigned int j = 0; j &lt; numDataValues2; ++j)
      {
          arraydata[21].intVal = data2[j].someValue;
          ... // etc.
  
          _recordset-&gt;raw_AddNew(fields, values);
          _recordset-&gt;Update();
      }
  }
  </code></pre>
  
  <p>However it is relatively slow. It can take a second to add a 1000 rows of data, which is just too long in our environment. If I comment out the calls to raw_AddNew and Update the logic flies. So the issue is with how I am adding the data to the recordset. Any suggestions or advice hugely appreciated. Big thanks in advance.</p>