Trying to export fields to excel. Have set the references to Excel 12, But, the i, j loop cuts short the number of fields to export to 10 the first time and then exports all 19 which results in an Excel file with duplicates.
Any ideas would be great. Thanks.
Code:
Imports Excel = Microsoft.Office.Interop.Excel.
Dim i As Integer
Dim j As Integer
Dim xlApp As Excel.Application
Dim xlWorkBook As Excel.Workbook
Dim xlWorkSheet As Excel.Worksheet
Dim misValue As Object = System.Reflection.Missing.Value
Dim sFileName As String = "tmp.xls"
xlApp = New Excel.Application
xlWorkBook = xlApp.Workbooks.Add(misValue)
conn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & Application.StartupPath & "\temp.mdb")
command = New OleDbCommand("SELECT * FROM Members", conn)
da.SelectCommand = command
da.Fill(ds, "Members")
'get active worksheet
xlWorkSheet = DirectCast(xlWorkBook.ActiveSheet, Excel.Worksheet)
xlWorkSheet.Name = "Members"
For i = 0 To ds.Tables(0).Rows.Count - 1
For j = 0 To ds.Tables(0).Columns.Count - 1
xlWorkSheet.Cells(i + 1, j + 1) = ds.Tables(0).Rows(i).Item(j)
Next
Next