Hi all
A while ago I wrote a code for an application that manipulate data using SQL query and displays the results on a grid now this time around i would like to have a button to export the results from the grid to excel
see the code below:
Imports System
Imports System.Data
Imports System.Data.OleDb
Public Class frmMain
Inherits System.Windows.Forms.Form
Private Const MAX_RECORDS As Integer = 10000
Private strConnect As String
Private Function GetFileName() As String
Dim NewFileName As String
Dim Newfile As OpenFileDialog = New OpenFileDialog()
Dim MyChoice As DialogResult
With Newfile
.Filter = "Access Files (*.mdb)|*.mdb|All Files (*.*)|*.*"
.FilterIndex = 1
.DefaultExt = "mdb"
.InitialDirectory = "C:\Documents and Settings\User\My Documents\Line.mdb"
.CheckFileExists = False
.ReadOnlyChecked = True
.Title = "Open Access Data File"
End With
MyChoice = Newfile.ShowDialog
If MyChoice = DialogResult.Cancel Then
NewFileName = ""
Else
NewFileName = Newfile.FileName
End If
If NewFileName.Length > 0 Then
Return NewFileName
End If
End Function
Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim FileName As String
Dim AdoConn As New ADODB.Connection()
Dim MyCat As New ADOX.Catalog()
Dim tbl As ADOX.Table
FileName = GetFileName()
If FileName.Length = 0 Then
Exit Sub
End If
Me.Text = "SQL LineSystem: " & FileName
strConnect = "Provider=Microsoft.JetOLEDB.4.0;Password="""";UserID=Admin;Data Source="
strConnect &= FileName
AdoConn.Open(strConnect)
MyCat.ActiveConnection = AdoConn
For Each tbl In MyCat.Tables
lstTables.Items.Add(tbl.Name.ToString)
Next
AdoConn.Close()
End Sub
Please assist
Mxo
South Africa
A while ago I wrote a code for an application that manipulate data using SQL query and displays the results on a grid now this time around i would like to have a button to export the results from the grid to excel
see the code below:
Imports System
Imports System.Data
Imports System.Data.OleDb
Public Class frmMain
Inherits System.Windows.Forms.Form
Private Const MAX_RECORDS As Integer = 10000
Private strConnect As String
Private Function GetFileName() As String
Dim NewFileName As String
Dim Newfile As OpenFileDialog = New OpenFileDialog()
Dim MyChoice As DialogResult
With Newfile
.Filter = "Access Files (*.mdb)|*.mdb|All Files (*.*)|*.*"
.FilterIndex = 1
.DefaultExt = "mdb"
.InitialDirectory = "C:\Documents and Settings\User\My Documents\Line.mdb"
.CheckFileExists = False
.ReadOnlyChecked = True
.Title = "Open Access Data File"
End With
MyChoice = Newfile.ShowDialog
If MyChoice = DialogResult.Cancel Then
NewFileName = ""
Else
NewFileName = Newfile.FileName
End If
If NewFileName.Length > 0 Then
Return NewFileName
End If
End Function
Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim FileName As String
Dim AdoConn As New ADODB.Connection()
Dim MyCat As New ADOX.Catalog()
Dim tbl As ADOX.Table
FileName = GetFileName()
If FileName.Length = 0 Then
Exit Sub
End If
Me.Text = "SQL LineSystem: " & FileName
strConnect = "Provider=Microsoft.JetOLEDB.4.0;Password="""";UserID=Admin;Data Source="
strConnect &= FileName
AdoConn.Open(strConnect)
MyCat.ActiveConnection = AdoConn
For Each tbl In MyCat.Tables
lstTables.Items.Add(tbl.Name.ToString)
Next
AdoConn.Close()
End Sub
Please assist
Mxo
South Africa