Solved

Save file to MS SQL Database

Posted on 2004-03-22
1
936 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

813 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now