Excel unable to insert more than 255 chars?

后端 未结 3 1383
故里飘歌
故里飘歌 2020-12-07 03:30

I am using OLE DB driver to insert more than 255 characters into an Excel sheet, but I get the error:

Exception Details: System.Data.OleDb.OleDbExcep

相关标签:
3条回答
  • 2020-12-07 04:24

    The link you are refering to, is about 256 columns and not characters. The 256 characters problem is described here with a workaround: http://support.microsoft.com/kb/213841

    0 讨论(0)
  • 2020-12-07 04:25

    My workaround to this issue is to add a text which its length is longer than 255 characters on the first row of the column. OleDB will treat this column as MEMO type and then it can insert more than 255 characters in a cell.

    0 讨论(0)
  • 2020-12-07 04:29

    I found a more efficient way to handle this problem, my references are the 2 links below

    http://support.microsoft.com/kb/316934

    http://www.codeproject.com/Articles/37055/Working-with-MS-Excel-xls-xlsx-Using-MDAC-and-Oled

    Basically do not use data adapter, data set and parameters to insert rows in the Excel (this never worked for me) instead run SQL insert from the code directly using command object

    Here what you have to do

    1. Declare the wide field as MEMO instead of string or CHAR "CREATE TABLE WorkSheetName ( field1 INT, field2 MEMO, field3 ... );"
    2. Build the insert statement like "INSERT INTO WorkSheetName (field1, field2, ...) VALUES (1234, 'Any long string here...', ...)"
    3. Declare a DbCommand to run the Create table and Insert statements above, here I am using the command obj from enterprise library

      DbCommand dbCommand = m_dbConnection.CreateCommand(); dbCommand.CommandText = "Create Table ..."; dbCommand.CommandType = CommandType.Text; dbCommand.ExecuteNonQuery();

      dbCommand.CommandText = "Insert Into ..."; dbCommand.CommandType = CommandType.Text; dbCommand.ExecuteNonQuery();

    0 讨论(0)
提交回复
热议问题