Solved

Save file to MS SQL Database

Posted on 2004-03-22
1
933 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 Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

759 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

20 Experts available now in Live!

Get 1:1 Help Now