开发者

Import query results into tool through VB.NET

开发者 https://www.devze.com 2022-12-20 00:11 出处:网络
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.

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 Wit开发者_JS百科h

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


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


The line

**.Refresh(BackgroundQuery:=False)** 'I am getting error here

is not correct and should be replaced by

.Refresh BackgroundQuery:=False

.

0

精彩评论

暂无评论...
验证码 换一张
取 消