Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Help with managing files in a database, using TADOTable and TDataSource.

Posted on 2004-09-08
9
Medium Priority
?
284 Views
Last Modified: 2013-12-03
I'm using Delphi 7, and i am writing a mail client.
I need an example code, showing how to manage files in a MS Access Database, using those two components.
What do i need to use? May be an OLE Object?
0
Comment
Question by:bbh2k3
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
  • +2
9 Comments
 
LVL 17

Expert Comment

by:Wim ten Brink
ID: 12004989
How do you want to do that? What do you mean by managing files? If you want to store emails in your database, then store them in their raw format, which happens to be ANSI-text. Also, use a TADOQuery instead since it offers a better performance.
0
 
LVL 17

Expert Comment

by:geobul
ID: 12005010
Hi,

Perhaps you are talking about managing tables not files. If so, what kind of management you are interested in? Be more specific please.

Regards, Geo
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 12005228
nothing to append ...  waiting for further info
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 26

Expert Comment

by:EddieShipman
ID: 12010297
I would think he means file attachments and how to post them to an Access database blob field.
0
 
LVL 17

Expert Comment

by:Wim ten Brink
ID: 12014466
Well, even file attachments are part of the raw email. They're just encoded as strings. All you need is a memo field... (Unless you're not retrieving emails in their raw format.)
0
 
LVL 26

Expert Comment

by:EddieShipman
ID: 12016217
Maybe he is decoding them and wants the capability to save the decoded file?

So bbh2k3, would you please enlighten us on your requirements?
0
 

Author Comment

by:bbh2k3
ID: 12035547
I want to store the email as ANSI text, i want to know how to store the attachment in a blob field, and extract it later.
0
 
LVL 17

Accepted Solution

by:
geobul earned 2000 total points
ID: 12038477
Hi,

The example below uses files from disk and a table with one OLE Object field named 'filebin'.

// adds one file to the table
procedure TForm1.btnSaveClick(Sender: TObject);
begin
  if OpenDialog1.Execute then begin
    with ADOTable1 do begin
      Open;
      Append;
      FieldByName('id').AsString := Edit1.Text; // id - string
      FieldByName('filename').AsString := OpenDialog1.Filename; // original filename - string
      TBlobFIeld(FieldByName('filebin')).LoadFromFile(OpenDialog1.Filename); // the content of the file
      Post;
      Close;
      ShowMessage('Done');
    end;
  end;
end;

// extracts the first file to disk
procedure TForm1.btnGetClick(Sender: TObject);
var
  s: string;
begin
  if SaveDialog1.Execute then begin
    s := Edit1.Text;
    with ADOTable1 do begin
      Open;
      First; // you'll have to replace this line with Locate or similar method for finding thhe record of interest
      TBlobFIeld(FieldByName('filebin')).SaveToFile(SaveDialog1.Filename);
      ShowMessage('Done');
      Close;
    end;
  end;
end;

The example doesn't contain errors handling at all.

Regards, Geo
0
 
LVL 17

Expert Comment

by:geobul
ID: 12038516
If you also want to remove the file from the table use:

TBlobFIeld(ADOTable1.FieldByName('filebin')).Clear;

but in that case it would be necessary to check if that field is empty before saving it to a file this way:

if not ADOTable1.FieldByName('filebin').IsNull then ...

Hope this will help you.

Best regards, Geo
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Suggested Courses

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question