SqlBulkCopy 不复制字符串> 255 个字符长

发布于 2024-07-17 14:11:22 字数 320 浏览 3 评论 0原文

我正在尝试将大型 Excel 电子表格复制到 SQL Server 数据库中。 我正在打开 Excel 电子表格的 OldDbConnection 并读取 [Sheet1$] 中的所有内容。 然后,我使用 OleDbCommand 获取包含电子表格数据的 IDataReader。

Excel 工作表中有多个单元格的文本内容超过 256 个字符。 但是,一旦使用 SqlBulkCopy 将其上传到数据库表,我只能看到数据库中这些 Excel 单元格的前 255 个字符。 数据库表字段的长度为 5000 个字符。

SqlBulkCopy 是否限制字段大小? 谢谢!

I am trying to copy a large Excel spreadsheet into the SQL Server database. I am opening an OldDbConnection to the Excel spreadsheet and reading everything from the [Sheet1$]. Then, I am using the OleDbCommand to get a IDataReader with the spreadsheet data.

There are several cells in the Excel sheet with text contents of more than 256 characters. But, once this gets uploaded to the database table using SqlBulkCopy, I only see first 255 characters from these excel cells in the database. The database table fields are 5000 characters long.

Does SqlBulkCopy limit the field size? Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

无敌元气妹 2024-07-24 14:11:22

根据我使用 ADO 数据连接的经验,将记录集的光标位置更改到客户端时,检索和发送大文本字符串可能会更好。

这里有一个简短的例子:

Dim rstADO As ADODB.Recordset
Set rstADO = New ADODB.Recordset
rstADO.CursorLocation = adUseClient

但是仔细观察您的帖子,我认为您当前没有使用 ADO,无论如何,如果您决定尝试在您的方法中使用 ADO,那么可能值得一看。 祝你好运!

in my experience with ADO data connections it may work better to retrieve and send large text strings when changing the cursor location of the recordset to client side.

here a short example:

Dim rstADO As ADODB.Recordset
Set rstADO = New ADODB.Recordset
rstADO.CursorLocation = adUseClient

but looking more closely at your post I think that you currently are not using ADO, anyways might be worth looking at if you decide to try to use ADO in your approach. Good Luck!

滥情空心 2024-07-24 14:11:22

我不知道 SqlBulkCopy 和 OldDbConnection。
但是 Excel 可能会给出前 255 个字符。
在 Excel 中,如果您使用 .value 属性访问单元格值,您将获得前 255 个字符,如果您使用 .text 属性访问它,您将获得全文。 希望这会给你一些想法。

I am not aware of SqlBulkCopy and OldDbConnection.
however Excel might be giving out first 255 chars.
In Excel if you access a cells value with .value property you get first 255 chars, and if you acccess it with .text property you get full text. Hope this will give you some idea.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文