使用 Excel 将 SQL 批量复制到 SQL Server,但进行数据修改
我正在阅读 SQLBulkCopy
并希望使用它将数千行从 Excel 文档导入到 SQL Server。我一直在阅读直接执行此操作而不修改数据的文章。在执行 SQLBulkCopy
之前,我需要对 Excel 文档中的数据进行一些修改和验证。可以这样做吗?我假设从重载中我可以修改数据并创建一个大型 DataTable
,并使用 WriteToServer
导入该 DataTable
。
I am reading up on SQLBulkCopy
and would like to use it to import thousands of rows from an Excel document to SQL Server. I keep reading articles that do it directly without modifying the data. I need to do some modifications and validations on the data in the Excel document before doing the SQLBulkCopy
. Is it possible to do this? I would assume from the overloads I can modify the data and create a large DataTable
, and import that DataTable
with WriteToServer
.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可能需要一个 DataReader 或 DataSet,可以在导入之前对其进行迭代以进行验证/修改。
此实用程序可能会帮助您 - http://exceldatareader.codeplex.com/
You probably want a DataReader or DataSet that you can iterate over for validation/modification before importing.
This utility might help you - http://exceldatareader.codeplex.com/
这对我来说效果很好:
This works fine for me: