Results 1 to 6 of 6
  1. #1
    Join Date
    Aug 2004
    Posts
    3

    Unanswered: Import data from a text file with DELPHI toward sql server

    Hello,

    Is there a way to import data from a text file with DELPHI toward a SQL Server table.

    I heard about BCP ...?

    Does someone know?


    THANKS.

  2. #2
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54
    I'll bet that one of us could figure it out, given a few more details. There are several ways to import text files into SQL Server, but BCP is a good place to start!

    -PatP

  3. #3
    Join Date
    Aug 2004
    Posts
    3
    Ok no problem,

    I have a table with one columns named 'insee' , I want to feed this table by extracting the value of this column from a text file.

    I want to automate the process from a DELPHI GUI.

    The GUI would seek through the arborescens the file, the user would choose the text file he want to import for ex 'data.txt' and click on 'import'

    Then the 'insee' column of 'data.txt' would be include in a one column table wich already exist on sql server.

    Thank you.

  4. #4
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54
    There are a number of ways to do what you want. I'll give you a few examples, and you can either pick one of them, or propose a new one.

    I think that the easiest way would be if the SQL Server can open the file using a UNC name. If that is the case, the server itself can do the BCP for you using a UNC to reach the file. This is very efficient, very low impact on the network, and easy to code.

    My next suggestion would be to have BCP available on each workstation running your Delphi program. You could then shell out to run BCP, sending the file directly from the workstation to the server. This is very secure, very low impact on the network, and easy to code.

    My last suggestion would be to write the application to use the Bulk Copy API to load the file. Personally this would probably be my first choice, but not everyone knows how to use the BCP API, and it isn't very straightforward the first few times that you use it. This is very secure, very low impact on the network, but it is not easy to code.

    One thing that you might want to consider is the kind of data you are moving, and its source and destination. There are some countries (notably France) where I'm pretty sure it is still a crime to BCP data across the border!

    -PatP

  5. #5
    Join Date
    Aug 2004
    Posts
    3
    Hello,

    Thank you Pat Phelan.

    I think I'm going to use bcp, even if I am in France lol

    I've made some try, but don't manage with bcp to import only one column of the text file.

    Ideed there is no pb if the table on my sql server has the same columns as the text file, but since the moment there are differents it does't work.

    Is there a way ( maybe with a particular format file .fmt) of importing only one column of the text file?


    Thank you!

  6. #6
    Join Date
    Jul 2003
    Location
    San Antonio, TX
    Posts
    3,662
    You'll need to replace IN woth FORMAT nad include "-f<format_file_name.ext>" to generate the format file. Then you can edit the format file to import only specific column(-s). Alternatively, you can generate the format file on the fly programmatically when user selects a file to import.
    "The data in a record depends on the Key to the record, the Whole Key, and
    nothing but the Key, so help me Codd."

Posting Permissions

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