c#,vb.net使用OleDb写入Excel异常:字段太小而不能接受所要添加的数据的数量

发布于:2025-05-28 ⋅ 阅读:(29) ⋅ 点赞:(0)

碰到问题:excel文件,有一列只是100来个字符,结果无法修改数据,除非给他清空内容

我的解决方法是:把数据导入到ACCESS处理,再设置加锁,多个IIS用户只能排队一个一个通过,因为ACCESS无法多线程写入,大部分大型数据库也没法多线程同时写入吧?

以下是网上找到的一些ADO相关的原因:


"the field is too small to accept the amount of data "_odbc字段太小而不能接受所要添加的数据的数量-CSDN博客
https://blog.csdn.net/u010032207/article/details/52171487

从Excel电子表格导入时,您会看到以下错误消息:
“[Microsoft][ODBC Excel驱动程序]字段太小,无法接受您尝试添加的数据量。请尝试插入或粘贴较少的数据”。

这是Excel ODBC驱动程序的问题,通常可以通过重新排序电子表格中的记录来解决。

从根本上说,Excel不是一个数据库,电子表格中的列没有与数据库相同的数据类型。Excel ODBC驱动程序必须对给定列的数据类型做出假设。驾驶员通过提前读取8条记录并查看找到的数据来实现这一点。然后,它根据读取的数据类型做出决定。当后续记录证明关于数据类型的假设是错误的时,就会出现问题。考虑两种情况…。

Excel电子表格中的列中有一列包含字符串数据。前8条记录包含短字符串(比如20-30个字符)。Excel ODBC驱动程序读取此数据,并假定短字符串数据类型适用于此列。如果后续记录包含更长的字符串(比如300个字符)。数据类型可能不合适,无法存储较长的字符串,上述错误是由Excel ODBC驱动程序引发的。将带有长字符串的记录移动到数据集的开头,将允许Excel ODBC为该列选择更合适的数据类型,该列将应用于电子表格中的所有记录。
电子表格中的列具有前8条记录的数字字符串,例如“123”、“456”等。Excel确定此列包含数字数据。后续记录包含一个非数字数据的字符串,例如“Hello World”。
Excel ODBC驱动程序所做的假设将被证明是不正确的,ODBC驱动程序将引发上述错误消息。这个问题可以通过重新考虑记录的顺序来解决。如果包含“hello world”的记录位于前8条记录中。Excel ODBC驱动程序将确定此列包含字符串数据,并希望选择适用于所有数据记录的字符串数据类型。
在所有情况下,该技术都是安排记录的顺序,以便允许Excel ODBC驱动程序正确选择数据类型。

============
While importing from an Excel spread sheet you see the following error message:
"[Microsoft][ODBC Excel Driver] The field is too small to accept the amount of data you attempted to add. Try inserting or pasting less data".

This is problem with the Excel ODBC driver which can often be worked around by reordering the records in the spreadsheet.

Fundamentally, Excel is NOT a database and the columns in a spreadsheet do not have a data type associated with them in the same way that that a database does. The Excel ODBC driver has to make an assumption about the data type for a given column. The driver does this by reading ahead 8 records and looking at the data found. It then makes a decision about the data type based upon what it has read. Problems occur when the assumption about data type is proven wrong by subsequent records. Consider two scenarios….
==============

A column in an Excel spreadsheet has a column in it which contains string data. The first 8 records contain short strings, (let's say 20-30 characters). The Excel ODBC driver reads this data and assumes that a short string data type will be appropriate for this column. If a subsequent record contains a longer string, (let's say 300 characters). The data type may prove inappropriate and unable to store the longer string and the error above is raised by the Excel ODBC driver. Moving the record with the long string to the beginning of the dataset will allow the Excel ODBC to select a more appropriate data type for the column which will apply to all records in the spreadsheet.
A column in a spreadsheet has numeric strings for the first 8 records, For example "123", "456" etc. Excel decides that this column has numeric data. A subsequent record contains a string which is not numeric data, for example "Hello World".

 The assumption made by the Excel ODBC driver will prove incorrect and the above error message will be raised by the ODBC driver. The problem can be worked around by reconsidering the order of the records. If the record containing "hello world" is placed within the first 8 records. The Excel ODBC driver will determine that this column contains string data and hopefully a string data type will be selected which will be appropriate for all data records.

In all cases the technique is to arrange the order of the records such that the Excel ODBC driver is allowed to make the correct selection of data type.


网站公告

今日签到

点亮在社区的每一天
去签到