• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 892
  • Last Modified:

How to insert a comma delimited text file into sql database

Hi,

I want the user to uploads a comma delimited text file to my site and i want insert it into the SQL database.

How do i upload the file?
How do i parse the text file?
how and should i convert it to XML file?

Thanks,
0
YuvalMel
Asked:
YuvalMel
  • 3
  • 2
1 Solution
 
HohlovDimaCommented:
Hi,
look at this article i think it will help
http://www.sqlteam.com/article/using-bulk-insert-to-load-a-text-file
Best Regards,
Dima.
0
 
HohlovDimaCommented:
You just need to use Bulk Insert.
0
 
YuvalMelAuthor Commented:
Thanks i did not kow that function.

if i have an error lets say duplicate key i will not know which element is zccount for it right?

and what if i want to know which element causes this, is there a way of knowing that with bulk insert?
0
 
HohlovDimaCommented:
Hi,
You can try to do such thing(make select from that set and do what you want)
SELECT a.* FROM OPENROWSET( BULK 'c:\test\values.txt', 
   FORMATFILE = 'c:\test\values.fmt') AS a;

Open in new window

If you only need to ignore duplicate keays you can use option IGNORE.
Best Regards,
Dima.
0
 
YuvalMelAuthor Commented:
Thanks Dima!
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now