如何在不使用批量插入查询的情况下导入文件csv? [英] how to import file csv without using bulk insert query ?

查看:73
本文介绍了如何在不使用批量插入查询的情况下导入文件csv?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用批量插入导入文件csv但它失败了,是否有另一种方法在查询中导入文件csv而不使用批量插入?

到目前为止这是我的查询但它使用批量插入:

批量插入[dbo]。[TEMP]来自'C:\Inetpub\vhosts\topimerah.org\httpdocs\SNASPV0374280960.txt',(firstrow = 2,fieldterminator = '〜',rowterminator ='');

解决方案

也许批量插入可以工作但你没有告诉确切的错误信息。



另一种方法是读取CSV文件你自己并发出INSERT命令。



阅读CSV文件我会建议这个解决方案:快速CSV阅读器 [ ^ ]



如果你需要一个关于如何进行INSERT的样本,你我会在这里找到一个: http://www.dotnetperls.com/sqlclient [ ^ ]

您可以在循环中为所有记录执行此操作,并将其包装为事务。

i have tried import file csv using bulk insert but it's failed, is there another way in query to import file csv without using bulk insert ?
so far this is my query but it use bulk insert :
bulk insert [dbo].[TEMP] from 'C:\Inetpub\vhosts\topimerah.org\httpdocs\SNASPV0374280960.txt' with (firstrow=2,fieldterminator = '~', rowterminator = ' ');

解决方案

Maybe the bulk insert could work but you didn't tell the exact error message.

An alternative would be to read the CSV file "yourself" and issuing INSERT-commands.

For reading the CSV file I would suggest this solution: A Fast CSV Reader[^]

If you need a sample for how to do INSERTs, you'll find one here: http://www.dotnetperls.com/sqlclient[^]
You would do that in a loop for all records and you should wrap it into a transaction.


这篇关于如何在不使用批量插入查询的情况下导入文件csv?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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