Click here to Skip to main content
15,891,943 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
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 = ' ');
Posted
Comments
Thanks7872 9-Jun-15 2:14am    
'it's failed' is in no way informational.

1 solution

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.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900