Home arrow Delphi-Kylix arrow Saving Files to a Database using Delphi: Saving Bitmaps to a Database
DELPHI-KYLIX

Saving Files to a Database using Delphi: Saving Bitmaps to a Database


In this series of articles I will discuss how to save and retrieve images and binary files to and from a database and recognize the format by reading the first four bytes of blob data. As usual I am using Borland Developer Studio 2006 (Delphi 2006) as the development platform and for the database server I will use MS SQL Server 2000. I intend to start from scratch and demonstrate how easily and quickly a database application can be created in Delphi by using its Data Access and Data-Aware components.

Author Info:
By: Danish Ahmed
Rating: 5 stars5 stars5 stars5 stars5 stars / 13
June 26, 2007
TABLE OF CONTENTS:
  1. · Saving Files to a Database using Delphi: Saving Bitmaps to a Database
  2. · Create a new project
  3. · More components
  4. · Creating the application

print this article
SEARCH DEVARTICLES

Saving Files to a Database using Delphi: Saving Bitmaps to a Database
(Page 1 of 4 )

In fact, you can create a simple but fully functional database application in Delphi without writing a single line of code! I will take you through a step by step demonstration of how to create a rudimentary database application in Delphi using data-aware components to save and retrieve bitmaps and other files to and from a database server and how to recognize the format of blob data by checking its first four bytes.

The very first thing we need to do is create a blank database called TestDB in the remote MS SQL server. You can use any other existing database on any other server but you will have to make sure that it has a blob field in one of its tables where you can save the image. My TestDB contains just one table with three fields: a primary key field, a BLOB field and a text field for image description. This is the SQL script used to create the table:

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[ImgTbl]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)

drop table [dbo].[ImgTbl]

GO

 

CREATE TABLE [dbo].[ImgTbl] (

[PKey] [int] IDENTITY (1, 1) NOT NULL ,

[Image] [binary] (16) NULL ,

[ImgDescription] [char] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL

) ON [PRIMARY]

GO

If you are using an older version of Delphi which requires you to access the database through BDE (Borland Database Engine) only, or for some reason you are using dbExpress (a simple and thin data-access layer providing connectivity to SQL database servers with the help of native drivers) to connect to the server, you have to make sure that a valid ODBC DSN(Data Source Name) has been created for the database and add that DSN in the dbExpress connections. If a valid DSN doesn't exist you can create one from the ODBC Administrator in the control panel.


blog comments powered by Disqus
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...

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 

Developer Shed Affiliates

 




© 2003-2017 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials