Parameters in SQL - Delphi 7

I am using Delphi 7 and Access 2007.

I want to know if anyone can show me how to use parameters with SQL and ADO statements.

What is the required encoding, etc. Sorry I'm new to Delphi.

+6
source share
1 answer

Just install the SQL query, and then fill in the parameters. Use parameter names that make sense to you, of course; I just used LastName and FirstName for an example. I updated to use TADOQuery instead of just TQuery after editing the question.

 ADOQuery1.SQL.Clear; ADOQuery1.SQL.Add('SELECT * FROM MyTable'); ADOQuery1.SQL.Add('WHERE LastName = :LastName AND'); ADOQuery1.SQL.Add('FirstName = :FirstName'); // Populate the parameters and open it ADOQuery1.Parameters.ParamByName('LastName').Value := 'Jones'; ADOQuery1.Parameters.ParamByName('FirstName').Value := 'James'; ADOQuery1.Open; // Use query results ADOQuery1.Close; // Populate parameters with new values and open again // Populate the parameters and open it ADOQuery1.Parameters.ParamByName('LastName').Value := 'Smith'; ADOQuery1.Parameters.ParamByName('FirstName').Value := 'Sam'; ADOQuery1.Open; // Use new query results ADOQuery1.Close; 
+9
source

Source: https://habr.com/ru/post/946527/


All Articles