joshua_123_99
asked on
How do I export a mysql query results to excel sheet?
Hi,
How do I export a mysql query result to an Excel sheet in Vb.net.This is my code until now:
How do I export a mysql query result to an Excel sheet in Vb.net.This is my code until now:
Imports MySql.Data.MySqlClient
Imports System.Data
Public Class FrmMain
Dim conn As MySqlConnection
Dim myCommand As New MySqlCommand()
Dim myAdapter As New MySqlDataAdapter()
Dim myData As New DataTable()
Dim SQL As String
Private myConnString As String
Public WriteOnly Property connectionString() As String
Set(ByVal value As String)
myConnString = value
conn = New MySqlConnection()
conn.ConnectionString = myConnString
Try
conn.Open()
Catch myerror As MySqlException
MessageBox.Show("Error Connecting to Database: " & myerror.Message)
End Try
End Set
End Property
Private Sub cmdRefresh_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdRefresh.Click
Dim conn As New MySqlConnection()
Dim myCommand As New MySqlCommand()
Dim myAdapter As New MySqlDataAdapter()
Dim myData As New DataTable()
Dim SQL As String
Dim Hash5 As XmlWriteMode
SQL = "SELECT filereputationsummary.fileMD5 FROM filereputationsummary" _
& " WHERE `numSubmissions`>100000" _
& " Order by `numSubmissions`;"
'conn = New MySqlConnection()
conn.ConnectionString = myConnString
Try
conn.Open()
Try
myCommand.Connection = conn
myCommand.CommandText = SQL
myAdapter.SelectCommand = myCommand
myAdapter.Fill(myData)
DGVReport.DataSource = myData
DGVReport.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells
'myData.WriteXml(Hash5)
Me.Show()
Catch myerror As MySqlException
MsgBox("There was an error reading from the database: " & myerror.Message)
End Try
Catch myerror As MySqlException
MessageBox.Show("Error connecting to the database: " & myerror.Message)
Finally
If conn.State <> ConnectionState.Closed Then conn.Close()
End Try
End Sub
End Class
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.