0

I have an odd problem. For example I load a file .xls with 10 rows and one of them has a long string in the column B, so sometimes it does not load the whole string in the dataGridView. According with the others rows of the excel's file is loaded the whole string or not.

Do you know why?

I hope I explained it well. Sorry my bad english.

Thanks

EDIT:

Here is my code to load the dataGridView:

    string connectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\test.xls;Extended Properties=""Excel 8.0;HDR=YES;""";

        DbProviderFactory factory = DbProviderFactories.GetFactory("System.Data.OleDb");

        DbDataAdapter adapter = factory.CreateDataAdapter();

        DbCommand selectCommand = factory.CreateCommand();
        selectCommand.CommandText = "SELECT * FROM [sheet1$]";

        DbConnection connection = factory.CreateConnection();
        connection.ConnectionString = connectionString;

        selectCommand.Connection = connection;

        adapter.SelectCommand = selectCommand;

        data = new DataSet();

        adapter.Fill(data);

        dataGridView1.DataSource = data.Tables[0].DefaultView;
Jason
  • 1,226
  • 12
  • 23
Panecillo
  • 43
  • 2
  • 8
  • 1
    It'd help if you include how you are associating the .xls file to the GridView. Are you using ODBC? COM Interop? Or something else? – Jacob Proffitt Nov 22 '11 at 17:48
  • [Duplicate](http://stackoverflow.com/questions/898513/excel-cell-values-are-truncated-by-oledb-provider)? – sq33G Nov 22 '11 at 23:08

1 Answers1

0

This is a limitation of the OLE Jet provider and typically is caused by the number of rows scanned to guess how long to make that field. You can edit your registry to extend that, but you'll take a performance hit if you have really long spreadsheets.

If this is, indeed, the problem, then you'll need to edit registry key "SOFTWARE\Microsoft\jet\4.0\Engines\excel" from 8 to 0.

Jacob Proffitt
  • 12,664
  • 3
  • 41
  • 47