I am populating an ADOdb recordset to Excel using C# interop.
while (!rs.EOF)
{
Excel.Worksheet xlMainWs = xlList.Find(x => x.Name.Equals("tMain"));
((Excel.Worksheet)xlMainWs).Select();
Excel.Range mainc1 = xlMainWs.Cells[refStartRow + 1, refStartCol];
Excel.Range mainc2 = xlMainWs.Cells[refStartRow + 1, refEndCol];
Excel.Range mainRng = (Excel.Range)xlMainWs.get_Range(mainc1, mainc2);
mainRng.ClearContents();
mainRng.CopyFromRecordset(rs, 1);
rs.MoveNext();
}
While I can populate the recordset to the excel range, the problem is it keeps populating the first row from the recordset. I tried putting:
rs.MoveNext();
but it's still populating the first row of the recordset.
I did the same in Excel VBA, the loop will move the record cursor to next record.
Why doesn't this work the same in C#?
rs.MoveNext();
?