简体   繁体   中英

How to Export data from SQL database into MS Excel

In my web application i want to download data directly from a SQL database to MS Excel with customize heading . In the web page there will be one textbox, user only choose the date from that textbox(this contain the pop up calender) and when user clicks on download button, it will directly download data into Excel. How can i achieve this?

You build a dataset from the sql query and conert the dataset to excel file using the code snippet shown in THIS link.

Response.ContentType = "application/vnd.ms-excel";
Response.AddHeader("content-disposition", "attachment;filename=MyFiles.xls");

Now turn off caching, or some browser may unable to download and open the file.

Hope it works for you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM