Importing Plain Text FIle to MS Acess Database

Ask a Question related to Coldfusion - Advanced Techniques, Design and Development.

  1. #1

    Default Importing Plain Text FIle to MS Acess Database

    I want to import Plain Text File into MS Access Database. The text file looks
    like this:

    A & A Drapery Ltd
    8314?134A Street?Surrey 604-597-8806
    A & A Spice House
    107?7045?128th Street?Surrey 604-592-0326
    A & A Survey
    13430?91st Avenue?Surrey 604-590-1754

    Each record is divided into two lines. The first line contains Company Name,
    second line contains address and phone. I would like to insert data in 3 dirent
    fields company, address and phone.

    Is it possible to do?

    Thank You

    DDhillon Guest

  2. Similar Questions and Discussions

    1. importing text automatically from a file or a database
      Hello all, I would like to import text from a file or database into an indesign document, automatically, in certain spaces of the document, what...
    2. Missing text sections in layout printed to plain text
      Hi - I am printing out one long text inserted (pasted) in a textbox in one body section which spans multiple pages. Within this text (source...
    3. [PHP] fopen() || Execute read file as php page; not plain text
      was able to use an absolute reference on my local machine to execute read file contents; e.g. fopen('http://www.mysite.com/index.php', 'a'), but...
    4. Content from a memo field: converting the rich text into plain text
      Hi folks, I have an Access 2000 db with a memo field. Into the memo field I put text with bold attributes, URL etc etc What I need to to is...
    5. Importing a text file into a database
      Hi If you are sure that the imported field names (BRO_CODE1, BRO-CODE1, BROCH_CODE1, etc) are *exactly* the same as your table field...
  3. #2

    Default Re: Importing Plain Text FIle to MS Acess Database

    Yes. If the file is not too big, you could use CFFILE to read the text file
    into a variable and then use a loop to read each line of the file (using the
    appropriate row delimiter). The odd numbered lines being the company name and
    even numbered lines being the address and phone number. You could then split
    the address and phone number fields (using the appropriate field delimiter ex.
    tab character) and insert each row into the database.

    mxstu Guest

  4. #3

    Default Re: Importing Plain Text FIle to MS Acess Database

    This is something along the lines of what you want to do.

    This creates an array with is all in, but you can modify it to upload to a DB.

    <cffile action="read" file="#CurrentFile#" variable="ThisData">

    <cfscript>
    // trim text file
    ThisData = Trim(ThisData);

    // create carriage return line feed
    CrLf = Chr(13) & Chr(10);

    // create array to hold data
    CompanyArray = ArrayNew(1);

    // current row
    CurrentRow = 1;

    // loop through file and get info
    for (i = 1; i LTE ListLen(ThisData, CrLf); i = i + 1) {
    // is this an address or a company name
    if (i MOD 2 IS 1) {
    // create new struct
    Company = StructNew();

    // add to array
    CompanyArray[CurrentRow] = Company;

    // this is a company name
    CompanyArray[CurrentRow].Company.Name = Trim(ListGetAt(ThisData, i, CrLf));

    }
    // this is an address
    else {
    // this is the trimmed address and phone number
    ThisContact = Trim(ListGetAt(ThisData, i, CrLf));

    // this is the phone number
    CompanyArray[CurrentRow].Company.Phone = Right(ThisContact, 12);
    // this is the address
    CompanyArray[CurrentRow].Company.Address = Left(ThisContact,
    Len(ThisContact) - 12);

    // next row
    CurrentRow = CurrentRow + 1;
    }
    }
    </cfscript>

    <cfdump var="#CompanyArray#">

    Stressed_Simon Guest

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139