Saturday, June 16, 2012

[JScript] ADODB GetRows to JScript

StackOverflow to the rescue again. Where would I be without them?

Anyway, I was looking up how to return a GetRows() call on an ADODB recordset to JScript and worked out the following from this posting about returning SafeArrays to JScript


function getRowsToMatrix( o ) {
  var vba = new VBArray( o );
  var dims = vba.dimensions();
  var result = [];
  for ( var i = vba.lbound(2); i <= vba.ubound(2); i++ ) {
   result[i] = [];
   for ( var j = vba.lbound(1); j <= vba.ubound(1); j++ ) {
    result[i].push(vba.getItem(j,i));
   }
  }
  return result;
 }

What I end up with is an array of arrays, which I can address as follows:


var X = getRowsToMatrix( oRS.GetRows() );
var recs = X.length;
var flds = X[0].length;
var lastFldLastRec = X[recs-1][flds-1]; // X is zero-based

Enjoy!



© Copyright Bruce M. Axtens, 2012

No comments: