SunQuest
 
       Delphi-Kylix
  Home arrow Delphi-Kylix arrow Page 3 - Saving Images and Binary Files to a Databa...
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Dedicated Servers  
Actuate Whitepapers 
VeriSign Whitepapers 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
DELPHI-KYLIX

Saving Images and Binary Files to a Database with Delphi 2
By: Danish Ahmed
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 3
    2007-07-03

    Table of Contents:
  • Saving Images and Binary Files to a Database with Delphi 2
  • Using Streams to save binaries
  • Retrieving BLOB data and saving to file
  • Checking the First 4 Bytes or Magic Numbers
  • Code

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT

    Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here

    Saving Images and Binary Files to a Database with Delphi 2 - Retrieving BLOB data and saving to file


    (Page 3 of 5 )

    So we have now successfully saved the file to the database but how do we retrieve it? You can use the TADOTable component itself to find the field or query for the record through the TADOQuery component by executing a SQL statement. However, I will introduce the TADODataSet component which can retrieve records directly from a table or from multiple tables through a SQL statement. You can connect to the server by specifying the connection parameters in its "ConnectionString" property but as I said earlier it is always advisable to connect through a single connection component. In my last article we used a TADOConnection component and created the connection string to connect to the  server.  Add the TADODataSet component to the form (available in the palette "dbGo") and set its 'connection' property  to ADOConnection1.

    We can utilize the CommandText property of ADODataSet1 to execute a SQL statement and access data in the returned recordset by accessing the component's properties and methods. The data in the blob field can be saved to any file. If you have a column with information on the type of file when it was saved as blob data, you can use the information to save the data to the same file type again. Here is a sample code to fetch a recordset matching the value assigned to the variable iPKey :

     ADODataSet1.Connection:=ADOConnection1;
     ADODataSet1.CommandText:='Select * From ImgTbl Where PKey=:param0';
     ADODataSet1.Parameters.ParamByName('param0').Value:=iPKey;
     ADODataSet1.Open;
     TBlobField(ADODataSet1 .FieldByNam('Image')).SaveToFile
                                   ('Img'+IntToStr(iPKey)+'.dat');

    More Delphi-Kylix Articles
    More By Danish Ahmed


     

    DELPHI-KYLIX ARTICLES

    - Client Dataset: Working with Data Packets an...
    - Using the Client Dataset in an N-Tiered Appl...
    - Using the Client Dataset in Two-Tiered Clien...
    - Using the Client Dataset in File-Based Archi...
    - Demystifying the Client Dataset
    - Working with INI Files in Delphi
    - Creating Data Link (UDL) Files in Delphi
    - Looking at the Details for an Invoicing Appl...
    - Invoicing in Delphi: Show Me the Money
    - Saving Images and Binary Files to a Database...
    - Saving Files to a Database using Delphi: Sav...
    - Creating CF Applications and Integrating a S...
    - Using Try and Finally to Help Prevent Memory...
    - The Implementation of an FTP Server
    - FTP Server: The Theory







    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway