Solved

Save file to MS SQL Database

Posted on 2004-03-22
1
944 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

691 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