none
ODBC Driver issue for .xlsx files in the Microsoft Excel Driver (*.xls, *.xlsx, *.xlsm, *.xlsb) ODBC driver. RRS feed

Answers

  • Hello x_ugang,

    If I understand correctly, you want know how to connect to excel file with ODBC.

    Since I do not know your PC environment, I do a sample with my PC environment like below and it works fine:

    public DataTable GetDataTable()
    
            {
    
                DataTable dt = new DataTable();
    
                OdbcConnection objOleDbCon = null;
    
                DataTable dtSheetName = new DataTable();
    
                string filePath = "E:\\BMX\\Lab\\SmapleFile\\2013-08-22B\\DataSource.xlsx";
    
                OdbcCommand objOleDbCmd = new OdbcCommand();
    
                OdbcDataAdapter objOleDbDataAdapter = new OdbcDataAdapter();
    
                DataTable dtExcelData = new DataTable();
    
                string xConnStr = "";
    
                xConnStr = "Driver={Microsoft Excel Driver (*.xls, *.xlsx, *.xlsm, *.xlsb)};DBQ=" + filePath + ";Extensions=asc,csv,tab,txt";
    
                objOleDbCon = new OdbcConnection(xConnStr);
    
                objOleDbCon.Open();
    
                try
    
                {
    
                    objOleDbCmd = new OdbcCommand("SELECT * FROM [" + "Course" + "$]", objOleDbCon);
    
                    objOleDbDataAdapter = new OdbcDataAdapter(objOleDbCmd);
    
                    objOleDbDataAdapter.Fill(dt);
    
                }
    
                catch (Exception ex)
    
                {
    
                    throw ex;
    
                }
    
                finally { objOleDbCon.Close(); }
    
                return dt;
    
            }

    My excel file data:


    The execute result:


    And my environment:

    Win8 64bit, VS 2012, .Net Framework 4.5.

    So could please share information regarding your environment so that we can help you better.

    Or have you downloaded the Office System Driver: Data Connectivity Components.

    And also we should not discuss neither the identical names of different files nor the misleading naming of a directory named something32 but contains 64-Bit-software like below:

    32-Bit Excel needs 32-Bit ODBC-Adminstrator odbcad32.exe which lives in C:\Windows\SysWOW64

    64-Bit Excel needs 64-Bit ODBC-Adminstrator odbcad32.exe which lives in C:\Windows\System32

    If this does not work for you, please let me know.

    Regards.


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Monday, September 30, 2013 5:42 AM
    Moderator