当从Excel插入数据集中的255个字符后,数据截断,但填充DataTable时没有问题 [英] Data truncating after 255 characters when inserting into dataset from Excel but no issue when populating DataTable

查看:133
本文介绍了当从Excel插入数据集中的255个字符后,数据截断,但填充DataTable时没有问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用ADO.NET将数据从Excel文件插入数据集。以下是采用的程序

I am trying to insert the data from Excel file to dataset using ADO.NET. Below is the procedure adopted


  1. 首先将所有excel数据都加载到数据集中,使用




connString =Provider = Microsoft.ACE.OLEDB.12.0; Data Source = mydb.xlsx;扩展属性= \Excel 12.0; HDR = Yes; IMEX = 2\;

connString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=mydb.xlsx;Extended Properties=\"Excel 12.0;HDR=Yes;IMEX=2\"";




  1. 当填充数据集时,它只插入255个字符。 (我找不到它截断的位置)。在我们的源代码中没有用于截断的代码。但是当使用相同的连接填充datatable时,不会出现此类问题。

请帮我解决这个问题

提前感谢

推荐答案

问题是ACE驱动程序在填充数据集时推断列的TEXT数据类型。文本列限制为255个字符。您需要强制它使用MEMO数据类型。当您填写数据库时,推测数据库列的类型可以支持超过255个字符,驱动程序会选择这些。

The problem is that the ACE driver is inferring a TEXT data type for the column when you're populating the data set. Text columns are limited to 255 characters. You need to force it to use the MEMO data type. When you're filling the database, presumably, the database column is of a type that supports more than 255 characters, and the driver picks that up.

除了在此线程上讨论的方法问题,您可以通过插入虚拟数据行并在该列的单元格中插入256个或更多字符来强制使用备忘录数据类型。 (那个线程关注Jet,但也应该适用于ACE。)

In addition to the methods discussed in this thread on the problem, you can force it to use the memo data type by inserting a dummy row of data and inserting 256 or more characters in the cell for that column. (That thread concerns Jet but should also be applicable to ACE.)

也许最好的选择是使用其他库来读取文件并填充DataSet,而不需要Jet / ACE。

Your best alternative, perhaps, is to use some other library to read the file and populate the DataSet without Jet/ACE.

这篇关于当从Excel插入数据集中的255个字符后,数据截断,但填充DataTable时没有问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆