FireDAC Components for Microsoft Dynamics 365

Build 22.0.8462

Manipulating Data

You can use TFDConnection or TFDQuery objects to execute data manipulation commands. A TFDQuery object is more efficient for executing a query repeatedly since you can prepare statements to skip statement processing on subsequent executions.

Using TFDConnection

You can use the ExecSQL method of the TFDConnection class as a quick way to execute data manipulation commands. You can pass in parameters through the overloaded method; however, the statement is not prepared.

Note that the TFDConnection object does not return result sets, so it is not suitable for SELECT statements. Note as well that the Connected property of the TFDConnection object needs to be set to true.

Update

The following example executes a parameterized update:

RowsAffected := FDConnection1.ExecSQL('update GoalHeadings set GoalHeadingId=:GoalHeadingId where GoalHeadingId = :GoalHeadingId', ['John',''test'']);

Insert

The following example executes a parameterized insert:

RowsAffected := FDConnection1.ExecSQL('insert into GoalHeadings (GoalHeadingId) values (:GoalHeadingId)', ['Jon Doe']);

Delete

The following example executes a parameterized delete:

RowsAffected:= FDConnection1.ExecSQL('delete from GoalHeadings set GoalHeadingId = :GoalHeadingId', [''test'']);

Using TFDQuery

TFDQuery objects can also return the rows affected by an operation and execute Prepared Statements. Use the ExecSQL method when no result set is returned. This method is overloaded. One way to invoke it is to specify the SQL statement in the SQL property:

FDQuery1.SQL.Text := 'update GoalHeadings set GoalHeadingId=:GoalHeadingId where GoalHeadingId = :GoalHeadingId';
FDQuery1.ParamByName('GoalHeadingId').AsString := 'John';
FDQuery1.ParamByName('GoalHeadingId').AsString := ''test'';
FDQuery1.ExecSQL;
RowsAffected := FDQuery1.RowsAffected;
Or, you can specify the statement and parameters as method arguments:
FDQuery1.ExecSQL('update GoalHeadings set GoalHeadingId=:GoalHeadingId where GoalHeadingId = :GoalHeadingId', ['GoalHeadingId', 'GoalHeadingId']);

Copyright (c) 2023 CData Software, Inc. - All rights reserved.
Build 22.0.8462