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

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());
            }

        }
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.