raj kadam

raj kadam

  • NA
  • 92
  • 7.5k

while importing access file it give format except in c#

Apr 4 2015 10:17 AM
i'm importing access (office 2010)file using c# this my code
string excelConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\medi.xlsx;Extended Properties=""Excel 12.0 Xml;HDR=YES""";
// string excelConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\\medi.xlsx;Extended Properties=Excel 12.0;";
string sqlConnectionString =ConfigurationManager.ConnectionStrings["sqlcon"].ConnectionString;
//Create Connection to Excel work book
OleDbConnection excelConnection = new OleDbConnection(excelConnectionString);
//Create OleDbCommand to fetch data from Excel
OleDbCommand cmd = new OleDbCommand
("Select * from [medi1$]",excelConnection);
excelConnection.Open();
OleDbDataReader dReader;
dReader = cmd.ExecuteReader();
// Create object for SqlBulkCopy
SqlBulkCopy sqlBulk = new SqlBulkCopy(sqlConnectionString);
sqlBulk.DestinationTableName = "demo";
 sqlBulk.WriteToServer(dReader);