2010-02-08 58 views
0

成果转化的工具,我正在写一个工具导入数据库查询结果到Excel中VB.NET导入查询通过VB.NET

我尝试下面的代码。它不工作。

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 

它在VBA中工作正常,但在VB.NET中没有问题。

+0

VBA不是VB.NET,它们是非常不同的语言。 – Oded 2010-02-08 11:01:19

回答

0

为什么不将查询结果加载到DataSet中,然后将DataSet表的内容导入到Excel中?

0

线

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

是不正确的,应该由

.Refresh BackgroundQuery:=False 

所取代。