locked
Import xls file into sql server database table in asp.net RRS feed

  • Question

  • User1062752276 posted

    I have one xls file which has 1.98 lacs rows. Whenever I try to import it in sql database table then I am getting following error to open OLE db connection.

    External table is not in the expected format.


    My code:

    string con = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + Server.MapPath("TowerWorkOrders20110316.xls") + ";Extended Properties=\"Excel 12.0\"";       
    
     //string con = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath("TowerWorkOrders20110317.xls") + ";Extended Properties=Excel 8.0";        
    
    OleDbConnection connection = new 
    OleDbConnection(con);        
    
    OleDbDataReader reader;        
    connection.Open();       
     OleDbCommand command = new OleDbCommand("SELECT * FROM [Sheet1$]", connection);        
    reader = command.ExecuteReader();.................


    Tuesday, April 12, 2011 2:34 AM

Answers