Forum Discussion
tristaanogre
13 years agoEsteemed Contributor
Essentially, if you have an SQL table returned as an ADODB.RecordSet, you could simply do something like:
That will effectively assign to the ExcelSheet at the indicated row and column the value of the current record at ColumnNo. I would probably wrap that in a while loop to loop through the recordset while !RecordSet.EOF and doing a for loop within that on the columncount of the record set. There's probably more than one way of doing it, though but that's how I'd end up doing it.
So, in PseudoCode, it might look something like this.
var Row=1;
var LoopIndex
while (!RecordSet.EOF)
{
for(LoopIndex = 1;LoopIndex<(RecordSet.ColumnCount); LoopIndex++)
{
ExcelSheet.Cells(Row, LoopIndex) = RecordSet.Fields(LoopIndex - 1).Value;
}
Row = Row + 1;
RecordSet.MoveNext;
}
This is untested code so it will need tweaks and makes some assumptions but this is what I would do. If this is not what you're looking for, could you be more specific in your need for guidance?