troubleshooting Question

exporting data

Avatar of frankie_jnr
frankie_jnr asked on
Visual Basic.NETVisual Basic Classic
12 Comments1 Solution220 ViewsLast Modified:
Hi all,

I have a datagrid that displays some data for me what i need to do now is add a button to export the data to a excel file. I am using vb.net 2005

Thanks for the help

Frank
myadapter = New MySqlDataAdapter
        myData = New DataSet
        Me.DataGridView1.Columns.Clear()
        Searchvalue = ""
        Searchvalue = InputBox("Enter Date", "Search", "", 100, 100)
        Dim conn As New MySqlConnection
        Dim cmd As New MySqlCommand
        conn.ConnectionString = _
                        "server=10.0.0.10;" _
                        & "uid=xxxx;" _
                        & "pwd=xxxx;" _
                        & "database=dnote_db"
        Try
            conn.Open()
            cmd.CommandText = "SELECT `time_entered`,`ord_nr`,`supplier`,`depot`,`product`,`qty`,`user_entered`,`time_printed` FROM data WHERE `depot` LIKE '%wenkem%' AND `time_entered` LIKE '%" & Searchvalue & "%' AND `log` NOT LIKE 'Original Row nr :' OR `depot` LIKE '%wenkem%' AND `user_entered` LIKE '%" & Searchvalue & "%' OR `depot` LIKE '%wenkem%' AND `time_printed` LIKE '%" & Searchvalue & "%' order by `time_entered`"
            cmd.Connection = conn
            myadapter.SelectCommand = cmd
            myadapter.Fill(myData)
            Me.DataGridView1.DataSource = myData.Tables(0)
            Me.DataGridView1.AutoResizeColumns()
 
        Catch ex As Exception
            MessageBox.Show(ex.Message, "Report could not be created", MessageBoxButtons.OK, MessageBoxIcon.Error)
        End Try
    End Sub
ASKER CERTIFIED SOLUTION
game-master

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 12 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 12 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros