954,574 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Button for exporting mysql table

Hello guys,

I found a lot examples about this one but I still don't have it all working.

So the thing is that I have a button in my C# web application called Export to Excel. The functionality should works as if the button is clicked - it just simply executes SQL command for exporting a table from database to xlsx file.
(maybe something like

SELECT * INTO OUTFILE "D:/table.xlsx"
FIELDS TERMINATED BY ','
FROM table;


Thanks a lot in advance

pepyrs
Light Poster
25 posts since Sep 2011
Reputation Points: 10
Solved Threads: 0
 

If anybody needs code for something like my problem, here is mine. I solved it ;)

//button for Exporting to Excel (.xls)
        protected void Button2_Click(object sender, EventArgs e)
        {
            try
            {
                string connectionString = "server=localhost; UserId=root; database=dbcss; ";
                MySqlConnection con = new MySqlConnection(connectionString);
                con.Open();

                //create sql command object
                string cmdText = "SELECT * INTO OUTFILE 'hui.xls' FROM management;";
                
                MySqlCommand cmd = new MySqlCommand(cmdText, con);

                cmd.ExecuteNonQuery();
                con.Close();

            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }

        }
pepyrs
Light Poster
25 posts since Sep 2011
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: