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.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Sharon WhitePosted Mar 24, 2013, 10:27 PM
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.
sanjeev pandeyPosted Mar 19, 2013, 7:17 AM
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.
Satyapriya NayakPosted Mar 15, 2013, 7:28 AM