Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to insert a file into a database?

Status
Not open for further replies.

sasogr

Programmer
Nov 6, 2003
3
MK
the problem is the following: in edit1 i have a filename taken from opendialog1. now i want to insert that file into a table called TABLE1, in the column SOLUTIONS. the falues of this column are alreadu definded as BLOB type.
 
I am assuming that you have a TTable setup pointing to TABLE1 named Table1.

Table1.Edit;
Table1.FieldbyName('SOLUTIONS').asString:=FileToString(Edit1.Text);
Table1.Post;


where FileToString is the following function:


function FileToString(const AFilename:string):string;
var
LSize:integer;
LStream:TStream;
begin
{Code a combinaton of TStrings.ReadFromFile and TStrings.ReadFromStream}
LStream:=TFileStream.Create(AFilename,fmOpenRead or fmShareDenyWrite);
try
LSize:=LStream.Size;
SetString(Result, nil, LSize);
LStream.Read(Pointer(Result)^, LSize);
finally
LStream.Free;
end;
end;

Have fun
Simon
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top