I am trying to import data from an Excel file to a table in SQL Server but it is throwing errors.
string ssqltable = "mytable";
string myexceldataquery = "select * from [Order Form$]";
try
{
string sexcelconnectionstring = @"provider=microsoft.jet.oledb.4.0;Persist Security Info=False;data source='C:\Users\usiddiqui\Desktop\myexcel.xlsx';extended properties=" + "\'excel 12.0;hdr=yes;\';";
string ssqlconnectionstring = "server=SANJSQL-DEV;Database=db; User Id=user; Password=pass;";
string sclearsql = "delete from " + ssqltable;
SqlConnection sqlconn = new SqlConnection(ssqlconnectionstring);
SqlCommand sqlcmd = new SqlCommand(sclearsql, sqlconn);
sqlconn.Open();
sqlcmd.ExecuteNonQuery();
sqlconn.Close();
OleDbConnection oledbconn = new OleDbConnection(sexcelconnectionstring);
OleDbCommand oledbcmd = new OleDbCommand(myexceldataquery, oledbconn);
oledbconn.Open();
OleDbDataReader dr = oledbcmd.ExecuteReader();
SqlBulkCopy bulkcopy = new SqlBulkCopy(ssqlconnectionstring);
bulkcopy.DestinationTableName = ssqltable;
bulkcopy.BatchSize = 100;
bulkcopy.WriteToServer(dr);
//while (dr.Read())
//{
// bulkcopy.WriteToServer(dr);
//}
dr.Close();
oledbconn.Close();
label1.Text = "File imported into sql server.";
}
catch (Exception ex)
{
//handle exception
}
the error comes on oledbconn.Open();
this is the error
Could not find installable ISAM.