0

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

1
Contributor
1
Reply
2
Views
5 Years
Discussion Span
Last Post by pepyrs
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 *[CODE][/CODE] INTO OUTFILE 'hui.xls' FROM management;";

                MySqlCommand cmd = new MySqlCommand(cmdText, con);

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

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

        }

Edited by mike_2000_17: Fixed formatting

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.