Solved

Save file to MS SQL Database

Posted on 2004-03-22
1
938 Views
Last Modified: 2007-12-19
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
0
Comment
Question by:mece
1 Comment
 
LVL 27

Accepted Solution

by:
kretzschmar earned 45 total points
ID: 10653011
try
 
TBlobField(DSTemp.FieldByName('EkFile')).LoadFromFile(St[8]);

>what is 50 for max filesize ? 50 byte ?
don't know yet, maybe

meikl ;-)
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Mobile Keyboard covers the display of the TMemo 3 95
Dynamically Created Query 3 62
How to build JSON File in Delphi 6 3 44
MS Access from Delphi 31 59
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…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…

791 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