How do I export a mysql query results to excel sheet?

Posted on 2008-06-09
Medium Priority
Last Modified: 2013-11-27

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
            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
                myCommand.Connection = conn
                myCommand.CommandText = SQL
                myAdapter.SelectCommand = myCommand
                DGVReport.DataSource = myData
                DGVReport.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells
            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)
            If conn.State <> ConnectionState.Closed Then conn.Close()
        End Try
    End Sub
End Class

Open in new window

Question by:joshua_123_99
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 53

Accepted Solution

Dhaest earned 375 total points
ID: 21748907
Exporting dataset to excel file.

Export to Excel using VB.Net

HOW TO: Transfer Data to Excel Workbook Using Visual Basic .NET

Export data table to Excel

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question