ASPForums.Net RSS Feedhttp://www.aspforums.net/Handlers/RSS.ashxLatest additions to the content that appears on ASPForums.Net(c) 2019 www.aspforums.com. All rights reserved.System.Data.OleDb.OleDbException: External table is not in the expected format in ASP.Net<p>Hi nedash,</p> <p>Use the below code to export DataTable to Excel. In this code you will not get the error while importing to database. But you have to keep one blank excel with atleast one sheet in the project folder in order to write the datatable to the excel and download that saved excel. Here i have Test.xls in the project folder. For this i have used using Microsoft.Office.Interop.Excel library.</p> <p><span style="text-decoration: underline;">Code</span></p> <pre class="brush: csharp">protected void Page_Load(object sender, EventArgs e) { DataTable dt = new DataTable(); dt.Columns.AddRange(new DataColumn[3] { new DataColumn(&#34;Id&#34;, typeof(int)), new DataColumn(&#34;Name&#34;, typeof(string)), new DataColumn(&#34;Country&#34;, typeof(string)) }); dt.Rows.Add(1, &#34;John Hammond&#34;, &#34;United States&#34;); dt.Rows.Add(2, &#34;Mudassar Khan&#34;, &#34;India&#34;); dt.Rows.Add(3, &#34;Suzanne Mathews&#34;, &#34;France&#34;); dt.Rows.Add(4, &#34;Robert Schidner&#34;, &#34;Russia&#34;); DataSet ds = new DataSet(); ds.Tables.Add(dt); ExportDataSetToExcelAndDownload(ds); } private void ExportDataSetToExcelAndDownload(DataSet ds) { // Initialize Excel Application Excel.Application excelApp = new Excel.Application(); // Open Existing Excel Excel.Workbook excelWorkBook = excelApp.Workbooks.Open(Server.MapPath(&#34;~/Test.xls&#34;)); foreach (DataTable table in ds.Tables) { // Get first worksheet Excel.Worksheet worksheet = excelWorkBook.Worksheets[1] as Excel.Worksheet; // Clear all data from first sheet worksheet.Cells.Clear(); // Adding columns to sheet for (int i = 1; i &lt; table.Columns.Count + 1; i++) { worksheet.Cells[1, i] = table.Columns[i - 1].ColumnName; } // Adding rows to sheet for (int j = 0; j &lt; table.Rows.Count; j++) { for (int k = 0; k &lt; table.Columns.Count; k++) { worksheet.Cells[j + 2, k + 1] = table.Rows[j].ItemArray[k].ToString(); } } } // Save Excel excelWorkBook.Save(); // Close Excel excelWorkBook.Close(); // Close Excel Application excelApp.Quit(); // Download saved Excel Response.ContentType = ContentType; Response.AppendHeader(&#34;Content-Disposition&#34;, &#34;attachment; filename=&#34; + DateTime.Now.ToString(&#34;yyyy-MM-dd&#34;) + &#34;.xls&#34;); Response.WriteFile(Server.MapPath(&#34;~/Test.xls&#34;)); Response.End(); }</pre> <p><span style="text-decoration: underline;">Namespace</span></p> <pre class="brush: csharp">using Excel = Microsoft.Office.Interop.Excel;</pre>https://www.aspforums.net:443/Threads/257395/SystemDataOleDbOleDbException-External-table-is-not-in-the-expected-format-in-ASPNet/https://www.aspforums.net:443/Threads/257395/SystemDataOleDbOleDbException-External-table-is-not-in-the-expected-format-in-ASPNet/Fri, 19 May 2017 02:00:15 GMT