HomeОбразованиеRelated VideosMore From: ProgrammingKnowledge

C# Tutorial 29:How to Export Data from Database To Excel File By using C#

112 ratings | 67781 views
Export Data from MYSQL table into excel sheet use of c#‎ Export to Excel using .net framework c# - exporting data to excel from my database Export Microsoft Access Data to Microsoft Excel using C#‎ Export dataTable to Excel from C#‎ Solutions to Export Data From Database to Excel in C# Exporting Data to Excel Export DataTable to Excel with Formatting in C# Export excel to database through c# How to export Sql Server Data to Excel File in C# Searches related to how to export database to excel in c# how to export data from datagridview to excel in c# c# export dataset to excel c# export to excel without interop export datatable to excel c# export to excel c# gridview c# export excel 2007 export to excel c# windows application java export data excel
Html code for embedding videos on your blog
Text Comments (30)
chevvuri sandeep (1 month ago)
could you please provide us the previous video link
Sheriff Audu (4 months ago)
hello, very good explanation, thank you but please i cannot find excel library on my visual studio all i saw was microsft.office.interop.excel and when i used this as my using statement it highlighted the values after the excel fullstop as wrong code. i am new to programming please help me
Mahmoud Ayman (5 months ago)
ExcelLibrary can be found here: https://code.google.com/archive/p/excellibrary/downloads cheers :D
HImanshu Prakash (5 months ago)
Please share previous videos links
Nova P (8 months ago)
hi nice vid, I have a small project can you help me out? whats ur hourly rate
sodipto Saha (1 year ago)
sir 2nd time click button error argument handled exception?how solve this problem?
George Stefanidakis (3 years ago)
The file that this tutorial created did not open in my version of Excel 2010. It showed a blank screen and nothing worked. Is there anything I can do to get this to work in my version of Excel?
jeen casandra (3 years ago)
what if i want to import data in sql using c# windows application?
Syawal Siregar (3 years ago)
Imanos Imanoss : so you will not exported twice,             cmd.ExecuteNonQuery();             DataTable dt = new DataTable();             SqlDataAdapter sda = new SqlDataAdapter(cmd);             sda.Fill(dt);             dataGridView1.DataSource = dt;             //sda.Update(dt);             DataSet ds = new DataSet("New_DataSet");             ds.Locale = System.Threading.Thread.CurrentThread.CurrentCulture;             //sda.Fill(dt); --> comment this, do not fill twice             ds.Tables.Add(dt);             ExcelLibrary.DataSetHelper.CreateWorkbook("MyExcelFiles.xls",ds);
Prince Verma (1 year ago)
Thanks a lot!!
priscilla urbano (3 years ago)
hi, can I change the path of the excel file?
Alsen Arthur (4 years ago)
I need a help...its show some error whn i run my application..like invalid cell value
Bob The Zealot (3 years ago)
use stackoverflow.com.
riiseborn (4 years ago)
hai.. i need help.. how to hide certain column that we unwanted without changing taking what from database. tq
Alexander Paniagua (4 years ago)
Nice, i perform my code just a liitle to give it a directory and a name to save. You just need to add a saveFileDialog to your form and then, on the clic event add this: saveFileDialog1.InitialDirectory = "";//you can give it C: D: E: F: etc saveFileDialog1.Title = "Save As Excel File"; saveFileDialog1.FileName = ""; saveFileDialog1.Filter = "Excel Files(2003)|*.xls|Excel Files(2007)|*.xlsx"; if (saveFileDialog1.ShowDialog() != DialogResult.Cancel) {               ExcelLibrary.DataSetHelper.CreateWorkbook(saveFileDialog1.FileName.ToString(), ds); } The only problem is the warning that throws when you try to open the file, i think it's because the .DataSetHelper.CreateWorkbook void function takes a dataset as a second parameter, parameter that must or should be converted to string in order to put it on the excel file, so that's why when you open it, it try to convert those values to show them in the file, that's what i think.
sodipto Saha (1 year ago)
thank you.. but when i click button 1st time save perfectly..but 2nd time when click button argument exception handled show? how to solve this problem??
Imanos Imanoss (4 years ago)
Thank you for your help, your videos were really so helpful for my project, but when i run the program and i guess for you too : i had my data exported twice on the excel file.....! For my application, i need to export my data to a cetain sheet on an excel file that already exsits and in which i saved some macros... So plz how can i export my datas to a sheet of that excel file (that i created before with macros) without creating a new one?
wilcar saturno (4 years ago)
i highly appreciate this tutorial but how can we export with null values..
Clarence (1 year ago)
We can alter the "select..." statement. The original one is "select * from database.edata; we can alter it to: select eid, name, surname, age, ifnull(`user_name`,''), ifnull(`password`,'') from database.edata; ifnull() is a reserved function in MySQL. it replaces the column in its first parameter with the values in the second parameter, when the first parameter is null. Hope this help.
Lars (4 years ago)
For each table create a new sheet: Worksheet worksheet = new Worksheet("First Sheet");
Lars (4 years ago)
In Office 2010 the Excel file is corrupt. To fix this problem, add like 100 rows to the file and it will open in Excel 2010. Or use Office 2007/OpenOffice. Here the code to generate 100 rows: for (int x = 0; x < 100; x++) { worksheet.Cells[x, 0] = new Cell("Row "+ x +"; Col: 0;"); } Great tutorials, very clear and understandable! Keep up the good work!!!
Milin Joshi (4 years ago)
Qiping Shen (4 years ago)
How to export multiple tables to one excel file? and in a given location?
Fahrettin Perçin (5 years ago)
To save the .xls file to a selected location, you need to create an instance of SaveFileDialog class. Then you need to show it with ShowDialog() and instead of writing a file name as parameter in CreateWorkbook() method, you need to write, "DataSetHelper.CreateWorkBook(|yourinstancename|.FileName, yourDataSet)"
Fahrettin Perçin (5 years ago)
Helpful video but Don't fill the DataTable instance twice. You've filled it while bringing table and before adding it to DataSet. It caused to repeat the same data twice as shown video.
Adnan Iqbal (5 years ago)
I created excel file by this tutorial but it is not opening ms excel says is a corrupt file data is corrupted and how can i save file on specified location and how to open correctly excel file should not be corrupted.
Mohammed Dawood Ansari (5 years ago)
One more thing about this, I am not able to find your ExcelLibrary Namespace.... Would please specify any reference or else for this...
Mohammed Dawood Ansari (5 years ago)
The Video and the Explanation is very good but why don't you upload your project file somewhere and pass the link to us to download....
hunt sing (5 years ago)
it would be better if can export all the values, including the null ones.
Vivek Singh (5 years ago)
could you tell us in a tutorial how to build barcharts and piecharts by taking the data from datagridview i am unable to do so. it would be helpful for me in my project. thanks in advance.

Would you like to comment?

Join YouTube for a free account, or sign in if you are already a member.