I want to import data from Excel sheet into MySQL through ASP .Net using c#
can anybody place a code?
Thanks
Abhijeet
Loading
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Satyapriya NayakRank #47 · 31.5K reputationPosted Mar 15, 2013, 3:28 AM EDT
sanjeev pandey30 reputationPosted Mar 19, 2013, 3:17 AM EDT
DataSet ds1 = New DataSet();
conn = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" + filename_import + ";" + "Extended Properties=Excel 8.0;"
OleDbConnection connection = New OleDbConnection(conn)
OleDbDataAdapter da = New OleDbDataAdapter();
OleDbCommand command = New OleDbCommand();
command.Connection = connection
command.CommandText = "SELECT * FROM [" + filenamess + "$]";
connection.Close();
connection.Open();
da.SelectCommand = command;
da.Fill(ds1, filenamess);
Steps-
1.first create a connection string for excel file(here filename_import full path name of the excel file).
2.the select query has filenamess which mean only file name without extension for example you have to write only if "c:\\data\\sanjeev.xls"
then use only sanjeev in filenamess.
3.the data set has been filled with data from the sanjeev.xls.
4.Then the dataset can be easily used to get data from excel file and u can either poulate datagridview or any other datasource though using dataset
it may be yours mysql.
Sharon White50 reputationPosted Mar 24, 2013, 6:27 PM EDT
You can import data from Excel into datatable firstly and then to MySQL.
Here is my code:
//Load File
workbook.LoadFromFile(Page.MapPath(@"./Data/EditChartSample.xls"),true);
Worksheet sheet = workbook.Worksheets[0];
//Import to DataTable
DataTable datatable = sheet.ExportDataTable();
My code is based on a .NET Excel component.