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).
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.
Next: More components >>
More Delphi-Kylix Articles
More By Danish Ahmed