Click here to Skip to main content
12,631,365 members (31,966 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C# MS-Excel
Hello every one, I am getting an error while importing data from excel sheet and binding that data to grid view.
Error: Could not find installable ISAM.

I think problem is in connection string.
This is my code:
string path = fileupload.PostedFile.FileName;
           string strmail = string.Empty;
           string connectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + path + ";Extended Properties=Excel 8.0;HDR=YES;ReadOnly=False;";
               
            OleDbConnection objConn = new OleDbConnection(connectionString);
            objConn.Open();//Here is the error
Posted 1-Feb-13 3:15am
Updated 1-Feb-13 3:17am
CHill60159.2K
v2
Comments
CHill60 1-Feb-13 8:22am
   
What is path actually set to ? Try putting quotes around it
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 4

hi


check the below code
public DataSet GetDataFromExcel(string filePath)
{
    try
    {
    string strConn;
    strConn = "Provider=Microsoft.ACE.OLEDB.12.0;" + "Data Source=" + filePath + ";" + "Extended Properties=\"Excel 12.0 Xml;HDR=YES;IMEX=1;TypeGuessRows=0;ImportMixedTypes=Text\"";
    DataTable dt = new DataTable();
    dt = null;
    using (OleDbConnection oleDB = new OleDbConnection(strConn))
    {
        oleDB.Open();
        dt = oleDB.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);
        if (dt == null)
            return null;
 
        ListItemCollection items = new ListItemCollection();
        int i = 0;
 
        //if (dt.Rows.Count > 1)
        //return null;  

        for (int rowIndex = 0; rowIndex < dt.Rows.Count; rowIndex++)
        {
            string excelSheetName;
            string lastCharacter = "";
 
            excelSheetName = dt.Rows[rowIndex]["TABLE_NAME"].ToString();
            excelSheetName = excelSheetName.Replace("'", "");
            lastCharacter = excelSheetName.Substring(excelSheetName.Length - 1, 1);
            if (lastCharacter == "$")
            {
                items.Add(dt.Rows[rowIndex]["TABLE_NAME"].ToString());
            }
        }
        if (items.Count > 1)
            return null;
 
        string sName;
        string query;
 
        sName = items[0].ToString();
        sName = sName.Replace("'", "");
        sName = sName.Replace("$", "");
 
        query = "";
        query = String.Format("select * from [{0}$]", sName);
        OleDbDataAdapter da = new OleDbDataAdapter(query, strConn);
        DataSet ds = new DataSet();
        da.Fill(ds);
        return ds;
    }
 
    }
    catch (Exception ex)
    {
 
        throw ex;
    }
}
 

 
public static DataSet ImportExceltoDataset(string file)
{
    IExcelDataReader iExcelDataReader = null;
 
    FileStream oStream = File.Open(file, FileMode.Open, FileAccess.Read);
 
    iExcelDataReader = ExcelReaderFactory.CreateBinaryReader(oStream);
 
    iExcelDataReader.IsFirstRowAsColumnNames = true;
 
    DataSet dsUnUpdated = new DataSet();
 
    dsUnUpdated = iExcelDataReader.AsDataSet();
 
    iExcelDataReader.Close();
 
    return dsUnUpdated;
}
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

OleDbCommand command = new OleDbCommand("SELECT * FROM [Sheet1$]", connection);
for more info check my blog here

http://dotnetdomain.blogspot.in/2010/06/how-to-store-excel-data-in-gridview.html[^]
  Permalink  
Comments
bapu_reddy 1-Feb-13 9:00am
   
I have modified the code as per ur suggestions. But getting the following error -- "External table is not in the expected format". So what should be the format. please help me. Thanks in advance.
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

Problem is regarding provider Microsoft.ACE.OLEDB.12.0
it is found in your system

you can use with .xls

string connectionstring = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\" + file + ".xls;Extended Properties=Excel 8.0;";

Source : Database Connection c# with sql/acess/excel[^]
Thanks
Hemant Singh
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 3

Please change your connection string like below
ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" App.Path & "\..\Upload" & ExcelFileName & ".xls" & ";Extended Properties=""Excel 8.0;HDR=NO;IMEX=1"""

Hope this helps
  Permalink  
v2

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web01 | 2.8.161205.3 | Last Updated 1 Feb 2013
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100