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  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
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 / 6
    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


    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

    - Loading an XML Document into the DOM
    - Delphi Wrapper Classes and XML
    - Delphi and the DOM
    - Delphi and XML
    - Internet Access: Client Service
    - Finishing the Client for an Internet Access ...
    - The Client for an Internet Access Control Ap...
    - User Management for an Internet Access Contr...
    - Important Procedures for an Internet Access ...
    - Server Code for an Internet Access Control A...
    - Constructing the Interface for an Internet A...
    - Building a Server Application for an Interne...
    - Building an Internet Access Control Applicat...
    - Client Dataset: Working with Data Packets an...
    - Using the Client Dataset in an N-Tiered Appl...







    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 1 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek