'lib Imports System.Data Imports System.Data.OleDb 'add references called microsoft.office.interop.excel 11 Imports Excel = Microsoft.Office.Interop.Excel 'btn export Dim cnn As OleDbConnection Dim cnnst As String Dim sql As String Dim i, j As Integer 'excel Dim xlapp As Excel.Application Dim xlworkbook As Excel.workbook Dim xlworksheet As Excel.worksheet Dim misvalue As Object = Reflection.Missing.Value xlapp = New Excel.Application xlworkbook = xlapp.workbooks.add(misvalue) xlworksheet = xlworkbook.sheets("sheet1") cnnst = "Provider=Microsoft.jet.OLEDB.4.0;Persist Security Info=False;Data Source=..\..\..\indigeneDB.mdb;" cnn = New OleDbConnection(cnnst) cnn.Open() sql = "select * from lga" Dim cmd As New OleDbDataAdapter(sql, cnn) Dim ds As New DataSet cmd.Fill(ds) For i = 0 To ds.Tables(0).Columns.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 xlworksheet.SaveAs("Sample_District.xlsx") xlworkbook.close() xlapp.Quit() Myobject(xlapp) Myobject(xlworkbook) Myobject(xlworksheet) cnn.Close() MessageBox.Show("The sample database was exported to 'Documents folder'")
ds.Tables(0).Columns(i).ColumnName;
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)