Click here to Skip to main content
15,901,122 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am Trying to convert Excel Doc to database I m using framework 3.5 and sql express 2008, when I m trying to run it is giving me following Exception :

"Could not find installable ISAM.."

the code I M using is :

SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["Homeconstr"].ConnectionString);
string path = FileUpload1.FileName.ToString();
string xlconst = @"Data Source=" + path + ";Provider=Microsoft.ACE.OLEDB.12.0; Extended Properties=Excel 12.0;";
OleDbConnection xlcon = new OleDbConnection(xlconst);
OleDbCommand xlcom = new OleDbCommand("Select * from [Sheet1$]", xlcon);
xlcon.Open(); //Exception Occuring here
OleDbDataReader dr;
dr = xlcom.ExecuteReader();
SqlBulkCopy bk = new SqlBulkCopy(con);
bk.DestinationTableName = "emp_tracker";
bk.WriteToServer(dr);
xlcon.Close();
Posted

1 solution

First, the path variable would just contain file name and not the full path. For that you would have to use Server.MapPath instead to resolve the path of the uploaded file. Which means you would have to store the uploaded Excel files in a specific location on the server and only then you can do a Server.MapPath.

Second, for your specific error this is what Microsoft has to say about it: Could not find installable ISAM[^]

Finally, as a suggestion, try not using this approach to import Excel data because you cannot guarantee if Excel would be installed on the server. This code would need Excel installed on the server to work. As an alternative, I prefer copying and pasting Excel data into a text box and on the submit or save button click, parse this delimited data into a list and then iterate over it saving each record to the database. This way you can easily control the execution and provide more robust error handling mechanism.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900