Solved

Binary File IO and ADO

Posted on 2003-11-10
2
436 Views
Last Modified: 2010-04-05
Hi,

I need to read a binary file into memory and insert it into my DB (via ADO). (I have never done IO in Delphi before.) Can anyone give me a piece of code to read a binary file into memory (efficiently) and also show me the best way to insert it into the DB...

Thanks a lot,
Marius
0
Comment
Question by:BarCode99
2 Comments
 
LVL 27

Accepted Solution

by:
kretzschmar earned 125 total points
Comment Utility
-define a blob-field in your table
use
Dataset.edit; //or insert
TBlobField(Dataset.FieldByName('YourFieldNameHere')).LoadFromFile('YourFileNameHere');
Dataset.Post;

if you need to load into memory

var
  ms : TMemoryStream;
begin
  ms := TMemoryStream.Create;
  try
    ms.LoadFromFile('YourFileNameHere');
    //maybe some processing with the in memory content
    ms.Position := 0; //spool back
    Dataset.edit; //or insert
    TBlobField(Dataset.FieldByName('YourFieldNameHere')).LoadFromStream(ms);
    Dataset.Post;
  finally
    ms.free;
  end;
end;

hope this helps

meikl ;-)
0
 

Author Comment

by:BarCode99
Comment Utility
Thanks meikl!

As usual you solve my problem...

Mairus
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
This video discusses moving either the default database or any database to a new volume.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

743 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now