I want to export data from an excel file to mysql database table. I use the following code to get the data from the excel file;
string path = label4.Text;
String connectionString = "Provider=Microsoft.ACE.OLEDB.12.0;" +
"Data Source=" + path + ";" +
"Extended Properties=Excel 12.0;";
OleDbConnection xlConn = new OleDbConnection(connectionString);
xlConn.Open();
OleDbCommand selectCommand = new OleDbCommand("SELECT * FROM [Sheet1$]", xlConn);
OleDbDataAdapter dataAdapter = new OleDbDataAdapter();
dataAdapter.SelectCommand = selectCommand;
DataTable dataSet = new DataTable();
dataAdapter.Fill(dataSet);
xlConn.Close();
This code works fine when 'Enable Editing' is ON on the excel file. But, it throws the following exception when 'Enable Editing' is OFF:
System.Data.OleDb.OleDbException: 'External table is not in the expected format'
How can I access the excel file even when 'Enable Editing' is OFF?The design of excel file is not on my hands. Thanks.