0

An unhandled exception of type 'System.Data.OleDb.OleDbException' occurred in System.Data.dll

Additional information: External table is not in the expected format.

if (comboBox1.SelectedItem.ToString() == "Comissioned Sites")
            {
                string pathConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + txtFilePath.Text + ";Extended Properties=\"Excel 8.0;HDR=Yes;\";";

                // Create Connection to Excel Workbook
                using (OleDbConnection connection = new OleDbConnection(pathConn))
                {
                    OleDbCommand command = new OleDbCommand("Select * FROM [" + txtSheet.Text + "$]", connection);

                    connection.Open();

                    // Create DbDataReader to Data Worksheet
                    using (OleDbDataReader dr = command.ExecuteReader())
                    {
                        // Bulk Copy to SQL Server
                        using (SqlBulkCopy bulkCopy = new SqlBulkCopy(con))
                        {
                            con.Open();
                            bulkCopy.DestinationTableName = "tblView";
                            bulkCopy.WriteToServer(dr);
                            con.Close();
                        }
                    }
                }
                MessageBox.Show("File Imported to Database Successfully");
            }

can anyone help me

Community
  • 1
  • 1
Umar E. Shaibu
  • 35
  • 2
  • 10

2 Answers2

0

Visit this page you may find what you are looking for Excel 2013 Connection Strings

Rahul Bhati
  • 276
  • 1
  • 8
0

Try modifying the column type in your Excel file.

Right click on the cell and click on Format cells -> select Date as a category.

It should work now as Oledb will read value as a Date type.

Rahul Bhati
  • 276
  • 1
  • 8