tags:

views:

37

answers:

1

hi

i have this code:

ConnectString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + ExcelFile + ";Extended Properties=\"Excel 12.0 Xml;HDR=No\"";
        SheetName = SheetName.Substring(0, SheetName.Length - 5);
        OleDbConnection Connection = new OleDbConnection();
        Connection.ConnectionString = ConnectString;
        try {Connection.Open();}
        catch (Exception EX)
        {
            MessageBox.Show(EX.Message);
        }
        OleDbDataAdapter Command = new OleDbDataAdapter("SELECT * FROM [" + SheetName + "$]", Connection);
        DataSet ExcelData = new DataSet();
        try {Command.Fill(ExcelData);}
        catch (Exception EX)
        {
            MessageBox.Show(EX.Message);
        }
        finally
        {
            if (Connection.State != ConnectionState.Closed)
                Connection.Close();
        }

but not all the data in column 1 insert - i get empty data why ? what can be wrong ?

thank's in advance

+1  A: 

When importing from Excel, datatypes for the columns are by default guessed based on the contents of the first eight rows. If the values are blank in the first 8 rows for a given column, that can result in no data for the column at all. This can be overridden in the registry. I would suggest investigating that possibility. Here's a good writeup.

http://blog.lab49.com/archives/196

cmsjr
yes !!! if i sort from the big-to the small value it works excellentbut how i can do it without sorting ?
Gold
update the registry key as described in that post. That will force the provider to read the entire file before assigning data types, so there could be a performance hit if you are dealing with very large files.
cmsjr
I update the registry key - but still don't work.maybe because i have Windows 7 ??
Gold
It may be that Windows 7 is looking for the value in a different registry location. I've never debugged this in a Windows 7 environment, but I'll let you know if I come up with anything.
cmsjr