Ask a Question related to Coldfusion - Advanced Techniques, Design and Development.
-
DDhillon #1
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
-
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... -
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... -
[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... -
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... -
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... -
mxstu #2
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
-
Stressed_Simon #3
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



Reply With Quote

