Results 1 to 3 of 3
  1. #1
    Join Date
    Feb 2007
    Posts
    3

    Unanswered: Dynamicallly Importing csv file into MS SQL

    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

  2. #2
    Join Date
    Feb 2007
    Posts
    38
    It's syntax error.
    Use () instead of {} as below:

    BULK INSERT Contact
    FROM 'C:\Import_data.csv'
    WITH
    (
    FIELDTERMINATOR = ',',
    ROWTERMINATOR = '\n'
    )

  3. #3
    Join Date
    Oct 2006
    Posts
    115
    if you still hit error, try to see if you have grant the right permission in Windows for your csv files.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •