Click here to Skip to main content
16,019,768 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

Does anyone know how to overcome the ACE/OLEDB 255 column import OLEDB restriction?

Tried to use a named range eg [Sheet1$A1:E10] but it did not work
Posted
Comments
Kenneth Haugland 20-Aug-12 0:44am    
It has restrictions? Use Interop.Excel then ;)
AU Jase 20-Aug-12 1:16am    
I cannot use threading with interop ! I need to use OLEDB

I havent heard any such restrictions so far, it could be your connection string issue.

Please try the following methods :
C#
public string GetConnectionString(string FileNamePath, bool HasHeader)
        {
            string ConnectionString = "";
            string Extension = Path.GetExtension(FileNamePath).ToLower();

            string BinaryExcelProvider = "Microsoft.Jet.OLEDB.4.0";
            string XmlExcelProvider = "Microsoft.ACE.OLEDB.12.0";
            string BinaryExcelExtProperties = "Excel 8.0";
            string XmlExcelExtProperties = "Excel 12.0";
            string XmlMacroExcelExtProperties = "EXCEL 12.0 Macro";

            string Provider = "";
            string ExtendedProperties = "";

            switch (Extension)
            {
                case ".xls":
                    Provider = BinaryExcelProvider;
                    ExtendedProperties = BinaryExcelExtProperties;
                    break;

                case ".xlsx":
                    Provider = XmlExcelProvider;
                    ExtendedProperties = XmlExcelExtProperties;
                    break;

                case ".xlsm":
                    Provider = XmlExcelProvider;
                    ExtendedProperties = XmlMacroExcelExtProperties;
                    break;
            }

            string Header = ";HDR=NO;IMEX=1";
            if (HasHeader)
                Header = ";HDR=YES;IMEX=1";
            string ConnectionStringFormat = "Provider={0};Data Source={1};Extended Properties=\"{2}{3}\";";

            ConnectionString = string.Format(ConnectionStringFormat, Provider, FileNamePath, ExtendedProperties, Header);
            return ConnectionString;
        }

public DataSet ReadWorkSheet(string excelFile)
        {
            Success = false;
            System.Data.DataSet excelDataSet = new DataSet();
            string connectionString = this.GetConnectionString(excelFile);


            using (OleDbConnection objConn = new System.Data.OleDb.OleDbConnection(connectionString))
            {
                try
                {
                    objConn.Open();
                    OleDbDataAdapter cmd = new OleDbDataAdapter("select * from [Sheet1$A1:E10]" , objConn);
                    cmd.Fill(excelDataSet, "MyData");
                    cmd.Dispose();
                }
                catch { }
                finally
                {
                    if (objConn != null)
                    {
                        objConn.Close();
                        objConn.Dispose();
                    }

                }
            }
 return excelDataset
}


Thanks,

Kuthuparakkal
 
Share this answer
 
v2
Comments
AU Jase 20-Aug-12 1:40am    
When I select 3 fields, from an excel file with 5-10 columns, SELECT [fieldA],[fieldB],[fieldC] FROM [Sheet1$] it works, but then I use a file >255 columns and try SELECT * FROM [Sheet1$C1:E10] it does not work
Kuthuparakkal 20-Aug-12 2:22am    
I see... Try this :
http://exceldatareader.codeplex.com/
Seems to be a problem that has no solution with regards to OleDb:
http://social.msdn.microsoft.com/Forums/eu/adodotnetdataproviders/thread/cf21f1be-d6e8-4ed9-b977-d6876bf0cf06[^]

Find another way of importing your data. Good luck ;)
 
Share this answer
 
Comments
AU Jase 20-Aug-12 1:49am    
My workaround was trying to use a SELECT a range, but its not working, so you are saying the SELECT range will not work ?

There are so called "solutions that say to read in 2 seperate parts and re merge the 2 data tables"?
Have a look at this article Exporting Data to Excel[^] Solution 1.
 
Share this answer
 
http://exceldatareader.codeplex.com/[^]

Will be a best fit here... I used this libaray extensively in the past... It works with all excel.. sometimes it may stop(very rare) then you open excel and save it again... it will pick it up... This lib is the best one so far.
 
Share this answer
 

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