Link to home
Start Free TrialLog in
Avatar of ahmed hakeem
ahmed hakeem

asked on

how to Save Files to data base

after open file dialog how could i save this file to DB

openDialog := TOpenDialog.Create(self);
  openDialog.InitialDir := 'D:\';
 openDialog.Options := [ofFileMustExist];
//
//  // Allow only .dpr and .pas files to be selected
 openDialog.Filter :=
   'All files (*.*)|*.*';
//  // Display the open file dialog
 if openDialog.Execute  then
 title:=openDialog.FileName;
  TFileStream.Create (title, fmOpenRead);
  dbAttach_Title.Value:=title;
  //'File : '+openDialog.FileName;
//  else ShowMessage('Open file was cancelled');
Avatar of Geert G
Geert G
Flag of Belgium image

1: depends on the database type
2: you want to save the contents ...

use a blobstream
https://edn.embarcadero.com/article/27462

another sample:
http://www.scalabium.com/faq/dct0141.htm
Avatar of ahmed hakeem
ahmed hakeem

ASKER

thank you,
but I used Varbinary(max) in sql
so I solved it as follow:
 fStream:=TFileStream.Create(OpenDialog.FileName,fmOpenRead);
    db.Edit;
     dbAttachment.LoadFromStream(fStream);
     Attachment_Title_Label.Caption:=ExtractFileName(OpenDialog.FileName);
       fStream.Free;
if you solve it ... can you close the question?
This question needs an answer!
Become an EE member today
7 DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.