Link to home
Start Free TrialLog in
Avatar of mece
mece

asked on

Save file to MS SQL Database

hi to all,

i want to save a file to a ms sql server database table
first i create a row
EkFile -> varbinary -> 50

then at delphi i wrote these lines

DSTemp: TAdoDataSet;
Blob: TStream;
fs: TFileStream;

if St[8] <> '' then
begin
  Blob := DSTemp.CreateBlobStream(DSTemp.FieldByName('EkFile'), bmWrite);
  try
    Blob.Seek(0, soFromBeginning);
    fs := TFileStream.Create(St[8], fmOpenRead or fmShareDenyWrite);
    try
      Blob.CopyFrom(fs, fs.Size);
    finally
      fs.Free;
    end;
  finally
    Blob.Free;
  end;
end;

it gives error "invalid typecast" at runtime
when below line executes
Blob := DSTemp.CreateBlobStream(DSTemp.FieldByName('EkFile'), bmWrite);

when i change Blob: TBlobStream
it gives error : Incompatible types TBlobStream and TStream

why ?

also
EkFile -> varbinary -> 50
what is 50 for max filesize ? 50 byte ?

thanx

MeCeX
ASKER CERTIFIED SOLUTION
Avatar of kretzschmar
kretzschmar
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial