使用OleDb寫入Excel異常,"字段太小而不能接受所要添加的數據的數量" "the field is too small to accept the amount of data "




解決方法:

excel是根據第一行數據來判斷數據類型的,所以你需要在第一行相應字段添加足夠長的字符串(隨便寫長一點就行,導入後可以刪除的嘛).

這個問題是Access數據庫字段默認長度是250,而你添加的數據大於250個字符,但是你是通過Access驅動引擎寫入到Excel的,所以你也無法改變數據類型.

在網上找問題,很多人都說改變Access字段數據類型,問題是我根本就沒有在Access上操作,而是通過Access驅動引擎寫入到Excel裏面.所以解決思路應該放在Excel上. 


這樣就搞定了.

還有一個異常:標準表達式中數據類型不匹配。

同理:原因就是第一行記錄爲空或者爲數字,所以要改爲字符串.將第一行記錄添加數據,


這是我在google找到的.

=============================

參考:https://www.inaplex.com/forum/yaf_postst4_Excel-ODBC-error----The-field-is-too-small.aspx

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….

  1. 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.
  2. 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.


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章