Adagio
8 years agoFrequent Contributor
Data provider or other service returned an E_FAIL status
Hello,
I'm trying to run a piece of code which copies data from a Database table and paste it in a spreadsheet.
But I get the error "Data provider or other service returned an E_FAIL status." at the highlighted line.
var dbTable = conn.Execute_(execQuery);
var excel = Sys.OleObject("Excel.Application");
var wb = excel.Workbooks.Open(fileName);
var ws = wb.Sheets.Item(sheetName);
excel.DisplayAlerts = false;
// Copy All field names
for (var i = 0; i < dbTable.Fields.Count ; i++)
ws.Cells.Item(1, i + 1).Value = dbTable.Fields.Item(i).Name;
// Scans all records returned by the query
Log.Message("Total Fields: " +dbTable.Fields.Count);
dbTable.MoveFirst();
var RowIndex = 2;
while (! dbTable.EOF)
{
for (i = 0; i < dbTable.Fields.Count; i++)
ws.Cells.Item(RowIndex, i + 1).Value = dbTable.Fields.Item(i).Value;
dbTable.MoveNext();
RowIndex++;Any suggestions or help would really be appreciated!
Thank you
Abhi