Have an amazing solution built in RAD Studio? Let us know. Looking for discounts? Visit our Special Offers page!
CodeDatabaseDelphiRAD Studio

Learn How Easy It Is To Connect To Microsoft SQL Server In Windows Delphi Development

This sample allows the user to create temporary connection definition at run-time and master-details relationship between datasets using TFDQuery to work with MSSQL databases.

Location

You can find the MSSQL sample project at:

  • Start | Programs | Embarcadero RAD Studio Sydney | Samples and then navigate to:
    • Object PascalDatabaseFireDACSamplesGetting StartedMSSQL
  • Subversion Repository:
    • You can find Delphi code samples in GitHub Repositories. Search by name into the samples repositories according to your RAD Studio version.

How to Use the Sample

  1. Navigate to the location given above and open GettingStarted.dproj.
  2. Press F9 or choose Run > Run.

Files

File in DelphiContains
GettingStarted.dproj
GettingStarted.dpr
The project itself.
fGettingStarted.pas
fGettingStarted.fmx
The main form.

Implementation

The sample implements the following features.

Creating temporary connection definition

The simplest way to configure connection to MS SQL database at run-time is to build a temporary connection definition:

In the sample, the temporary definition is created when clicking the Connect button.

Master Details

In the demo database, the Categories and Products tables have one-to-many relation by CategoryID field. The qryCategories.SQL property is set up as follows:

In addition, the qryProducts.SQL property is set up as follows:

Finally, the qryProducts.MasterSource property is set to dsCategories, while the MasterFields property is set to CategoryID. This creates a master-details relationship between the datasets.

Executing queries

Simple queries execution is demonstrated via ExecSQL method of TFDConnection.

Inserting a record providing parameters of various types:

Updating records:

Deleting a record:

Getting a scalar value from the database:

If you want to check the original post of this sample, please visit the link below:

http://docwiki.embarcadero.com/CodeExamples/Sydney/en/FireDAC.MSSQL_Sample

Head over and check out the full source code for connecting to Microsoft SQL Server in a Delphi Windows app.


Reduce development time and get to market faster with RAD Studio, Delphi, or C++Builder.
Design. Code. Compile. Deploy.
Start Free Trial   Upgrade Today

   Free Delphi Community Edition   Free C++Builder Community Edition

Related posts
C++DelphiNewsRAD Studio

RAD Studio 10.4.2 Silent Installer Makes It Easy To Automate The Installation Process

C++Delphi

Create Native And Secure iOS Wallet Enabled Apps With Delphi And C++ Builder

C++Delphi

GameDev: Fun Multi-Platform Mars Rocket Game For Android, iOS, macOS, And Windows

DelphiShowcase

Exciting Crossword Puzzle Android App Is Made In Delphi

2 Comments

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

IN THE ARTICLES