private void WriteExcel(DataTable dataTable) { string docupath = ConfigurationManager.AppSettings.Get("LMSFilePath"); string filePath = MapPath(docupath); string connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + filePath + ";Extended Properties=Excel 8.0;"; OleDbConnection connection = new OleDbConnection(connectionString); try { connection.Open(); DataTable MyTable = dataTable; string nonQuery = "INSERT INTO [Sheet1$] IN 'filePath' 'Excel 12.0;' SELECT * FROM [MyTable]"; //set up first query OleDbCommand selectCommand = new OleDbCommand(nonQuery); selectCommand.Connection = connection; selectCommand.Transaction = connection.BeginTransaction(); selectCommand.ExecuteNonQuery(); selectCommand.Transaction.Commit(); connection.Dispose(); connection.Close(); } catch (Exception) { }
selectCommand.ExecuteNonQuery();
The Microsoft Jet database engine could not find the object 'MyTable'. Make sure the object exists and that you spell its name and the path name correctly.
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)