Home arrow Delphi-Kylix arrow Page 2 - 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 / 7
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

TOOLS YOU CAN USE

advertisement
Saving Files to a Database using Delphi: Saving Bitmaps to a Database - Create a new project
(Page 2 of 4 )

Once you have set up the database, fire up Delphi and create a new project. We will need to drop some VCL components on the form to start building our application. I will try to give a very brief overview to the various components we are going to use.

Since our priority at the onset will be to ensure that our application can access the database server, we will start with the connection components. As is common with Delphi, there is more than one way to connect to the database from your application, but I will begin with a discussion of connecting through ADO components since that seems to be the preferred approach for most developers, including me.

ADO can connect to the server using both OLE DB provider for ODBC drivers and OLE DB provider for SQL Server, so we don't have to worry about whether or not a valid DataSource name for the database has been created if we are using the latter. Now back to the ADO components we are going to use and a brief description of each. (Please note that I am leaving the components with their default names, that is, the first instance of TADOConnection is named ADOConnection1).

TADOConnection The Connection component is necessary for establishing a connection to the database and interfacing the data store with the dataset. Further, the methods and properties of the Connection object can be useful in ensuring that all components access the database using one connection which is under proper control. You can specify which database you want to connect to by creating a connection string for the ADOConnection component.

To create a connection string of an ADOConnection1 component, right click on the dropped component and select "Edit ConnectionString" or click the ellipsis button for the ConnectionString property in the Object Inspector. The Connection String Editor pops up; if you intend to use the DSN select the data source name from the drop-down box and make sure you select the correct Data Source Name. Enter username and password if necessary and specify the default catalog, and then click on "Test Connection" to make sure that you can connect to the database.

However, creating a Data Source Name and then connecting to the server through it would not only be a lengthier process but unnecessary too since we can directly connect to the server with the OLE DB provider for MS SQL rather than depending on the ODBC driver to make the connection. To connect to the database server directly, select the provider tab in the Connection String Editor (Data Link Properties), then from the list of providers select "Microsoft OLE DB Provider for SQL server" and click next. Select the server name from the list of available servers; the database lookup box lists all databases available on the server. Select the one with which you want to work; in our case, that would be TestDB. Also make sure you allow for saving the password after you have entered one (or left it blank for the default). Finally click on the Test Connection; a message box informs you if the connection was successful.

Once a valid ConnectionString has been provided, the ADOConnection1 object can be used to connect to the database by setting its Connected property to true or calling the "Open" method. Please note that if you don't want the login dialog displayed to the user every time you need to set the "LoginPrompt" property to false and must have provided the credentials in the connection string.


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...

Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 



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