Click here to Skip to main content
15,891,431 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
Hello,

How to export all tables from an SQL Server Database into Excel - A sheet for each table, using c# asp.net?

Please help me.

Thanks in Advance.

Ankit Agarwal
Software Engineer
Posted
Comments
Naveen.Sanagasetti 15-Sep-15 8:47am    
What you tried so far..?

Agarwal1984 15-Sep-15 8:50am    
I don't know, how will be do this task, i have done simple sql single table to excel, but now i will be export complete database table backup into the excel worksheet.
Naveen.Sanagasetti 15-Sep-15 8:53am    
The Answer is simple previously you done with static data, now you need to implement the same with dynamic data.

First note down the plan in one paper and proceed..

Step 1 : Whether DataBase is static one or dynamic one
Step 2 : prepare SP for getting all the tables against Database
Step 3 : Prepare select queries against each table
Step 4 : once you made query then get the result into DataSet.
Step 5 : using DataSet, you can read the data into Excel sheet.

Achieve the requirement by splitting into small small modules like above and achieve your goal.
Sinisa Hajnal 15-Sep-15 9:21am    
Why do you need to do it through the code? There are perfectly good tools for exporting in most database manager programs.
Thanks7872 15-Sep-15 9:26am    
Look at one of these and proceed : https://www.google.co.in/webhp?sourceid=chrome-instant&ion=1&espv=2&ie=UTF-8#q=sql%20to%20excel%20c%23.

Come back when you stuck somewhere.

1 solution

- Execute your query
- Get your DataSet with all the desired tables
- Execute the function ExportDataSetToExcel from the following link

Export DataSet into Excel using C# Excel Interop
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900