Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

The Database Forum


You are currently viewing our The Database Forum as a guest. Please register to participate.
Login



Reply
Dynamically Importing csv file into MS SQL
Old 02-14-2007, 10:48 AM Dynamically Importing csv file into MS SQL
Junior Talker

Posts: 1
Trades: 0
I have an app written in delphi v5 with a MS SQL Database and I'm struggling with an import feature i need

The user needs a function to import Contact data from a txt/csv file into the Contact Table

Details of feature:
the user enters the different parameters into the Delphi app e.g.
File Location
Files Includes Column Headings or not
Whether the file Comma or Tab Seperated
Mapping the fields

Then i need to use those parameters and run some sort of import routine putting the data into the specific table.

The tables consists of 3 fields - First Name, Surname, Mob Number - but these fields can be in any order in the file. for example Col 1 (in file) needs to go into Field 3 in DB. this is sorted in the Mapping Fields above

How do I do this using MS SQL??

I've been looking at using the BULK INSERT command e.g
BULK INSERT Contact
FROM 'C:\Import_data.csv'
WITH
{
FIELDTERMINATOR = ',',
ROWTERMINATOR = '\n'
}
but at the minute i just get error -
[Microsoft][ODBC SQL Server Driver]Syntax error or access violation.

Is this the correct command to use??

Do you know any websites that can point me in the right direction??

Thanks
minckle is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 02-14-2007, 03:31 PM Re: Dynamically Importing csv file into MS SQL
ForrestCroce's Avatar
Half Man, Half Amazing

Posts: 3,023
Name: Forrest Croce
Location: Seattle, WA
Trades: 0
I'm guessing you're using SQL Server 2000, or possibly ( but not likely ) '97. If it's 2005 this advice doesn't apply.

Use DTS. It's not "very" simple, but it's easier than the bulk insert you're trying to run. You can do most everything with the mouse, including column mappings ... which say that column 1 in the CSV file corresponds to column 3 in your table.

Also, it sounds like you're working on an application, and going to let the user add a variety of data formats. You would probably create a separate DTS package for each, and then run one from the command line, depending on what the user enters ( comma vs tab, whatever else ).

You can find out more about DTS in "Books Online."
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
ForrestCroce is offline
Reply With Quote
View Public Profile Visit ForrestCroce's homepage!
 
Reply     « Reply to Dynamically Importing csv file into MS SQL
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.73850 seconds with 12 queries