Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 166
  • Last Modified:

how can i change a txt file to date base file?

how can i take an infomation from txt file
and add it to the DB information?
please give me an example and
source.
0
tomerlei
Asked:
tomerlei
  • 7
  • 4
  • 2
  • +2
1 Solution
 
mvz121697Commented:
This example reads in the file c:\test.txt in a table
(Before use, drop a table (Table1) on your form, and connect it to the database/tabel)


Var F:TextFIle;
   cFile,cLine,cField1,cField2:string;

cFile:='c:\test.txt';
Assign(F,cFIle);
try
 reset(F);
 while not eof(F) do begin
   Readln(F,cLine);
   cField1:=Copy(cLine,1,10);
   cField2:=Copy(cLine,11,10);
   cField3:=Copy(cLine,21,10);
   Table1.Append;
   Table1.FieldByName('Field1').asstring:=cField1;
   Table1.FieldByName('Field2').asstring:=cField2;
   Table1.FieldByName('Field3').asinteger:=StrToInt(cField3);
   Table1.Post;
 end;  
Finally
  CloseFile(f)
end;


Greetings
MvZ
0
 
tomerleiAuthor Commented:
but it says:
incompaible types 'TPersistent' and 'text'
and he take the curser to the assign command.
What need i do
0
 
tomerleiAuthor Commented:
<h1>answer me please</h1>
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
itamarCommented:
Hi tomerlei,

there is another approach to this question. With BDE you can map a text file and treat it almost exactly as a local table. Associating with all controls that deals with a "real" data table. If your interested I can give you more details.

Bye,
Itamar
0
 
interCommented:
In mvz's answer use AssignFile not Assign (which is a method for opening files before delphi-BP7.0- etc.) And add the following for trimming extra spaces. This example assumes that you have three fields in text file in three columns. Field one is first 10 chars, fields to is chars between 10 and 21, etc...

...
cField1:=Trim(Copy(cLine,1,10));
cField2:=Trim(Copy(cLine,11,10));
cField3:=Trim(Copy(cLine,21,10));
...

Igor
0
 
ZifNabCommented:
Why don't you just store the contents of that txt file in a Memo field of tTable?
0
 
mvz121697Commented:
Sorry, for the delay, but like 'Inter' said,
i made a mistake in with assign (should be assginFile)
(I typed it out-of-the head).

Greetings,
MvZ
0
 
tomerleiAuthor Commented:
and how the text file should  to be.
my fields is:
Company
First name
Last name
City
Street
Street num
Zip/postal code
0
 
tomerleiAuthor Commented:
and how the text file should  to be.
my fields is:
Company
First name
Last name
City
Street
Street num
Zip/postal code
0
 
mvz121697Commented:
In my previous example i was referring tto a textfile where
all the fields of a record where on 1 line, with fixed
field-length's
If the fieldss are on seperate lines in you're text file then
use something like this:

while not eof(F) do begin
  Table1.Append;
  Readln(F,cLine);
  Table1.FieldByName('Company').asstring:=cLine;
  Readln(F,cLine);
  Table1.FieldByName('Firstname').asstring:=cLine;
  Readln(F,cLine);
  Table1.FieldByName('Lasyname').asstring:=cLine;
  Readln(F,cLine);
  Table1.FieldByName('City').asstring:=cLine;
  Readln(F,cLine);
  Table1.FieldByName('Street').asstring:=cLine;
  Readln(F,cLine);
  Table1.FieldByName('Street num').asstring:=cLine;
  Readln(F,cLine);
  Table1.FieldByName('Zip').asstring:=cLine;
  Table1.Post;
end;

Greetings,
MvZ

0
 
tomerleiAuthor Commented:
thank you mvz!!!
but answer me this i want to give you the points!!!

0
 
tomerleiAuthor Commented:
mvz
Do you remember that i asked you how can i search a word
on a DBgrid?
it's locate me on one word.
i need
that when i click the button agian
it's find me the next word.  
0
 
tomerleiAuthor Commented:
how can i do that?






























































0
 
itamarCommented:
Hi tomerlei,

there is another approach to this question. With BDE you can map a text file and treat it almost exactly as a local table. Associating with all controls that deals with a "real" data table. If your interested I can give you more details.

Bye,
Itamar
0
 
mvz121697Commented:
> Thank you mvz!!!
but answer me this i want to give you the points!!! <

Ok.
For the Locate / Findnext question,
maybe you can use the Table's - filter property to show only the
lines which have the words. Then you can simple do a
Table.next

Greetings,
MvZ
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 7
  • 4
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now