tags:

views:

22

answers:

1

I am writing a tool to import a database query results into Excel in VB.NET

I tried the following code. It is not working.

 With objApp.ActiveSheet.QueryTables.Add(Connection:="ODBC;DSN=Build_statistics;", _
    Destination:=objApp.Range("G15"))
        .CommandText = "SELECT * from mytable"

        .Name = "Query"
        .FieldNames = True
        .RowNumbers = False
        .FillAdjacentFormulas = False
        .PreserveFormatting = True
        .RefreshOnFileOpen = False
        .BackgroundQuery = True
        .RefreshStyle = Microsoft.Office.Interop.Excel.XlCellInsertionMode.xlInsertDeleteCells
        .SavePassword = False
        .SaveData = True
        .AdjustColumnWidth = True
        .RefreshPeriod = 0
        .PreserveColumnInfo = True
        **.Refresh(BackgroundQuery:=False)** 'I am getting error here
    End With

It is working fine in VBA, but not in VB.NET.

A: 

Why not load the query results into a DataSet and then import the contents of the DataSet table into Excel?

Logan Young