From Clomosy Docs

Revision as of 11:09, 13 February 2024 by ClomosyManager (talk | contribs)

To connect to a SQL Server database using the DBSQLServerConnect component in Clomosy, you can follow these basic steps:

  • Set the SQL Server Connection String:

First, you'll need to prepare the connection string that you'll use to connect to the SQL Server database. This string should include the name of the SQL Server, the database name, authentication credentials, and other connection details.

Clomosy.DBSQLServerConnect('SQL Server','server_name','user_name','user_password','database_name',port);
  • Define the TUniQuery component:

To execute queries in SQL Server, you can use the TUniQuery component. It is defined within your application.

var
LocalQ:TUniQuery;
  • Specify the SQL query you want to run:
LocalQ := Clomosy.DBSQLServerQueryWith('SELECT model AS Product_Model FROM OperatingSystem');
  • To go to the first record in the query's result set:
LocalQ.First;
  • To advance to the next record in the data access component:
LocalQ.Next;

Example:

Base Syntax
 Var
 LocalQ:TUniQuery;
 
 begin 
   Clomosy.DBSQLServerConnect('SQL Server','server_name','user_name','user_password','database_name',1433);
   LocalQ := Clomosy.DBSQLServerQueryWith('SELECT model AS Product_Model FROM OperatingSystem');
   LocalQ.First;
   with LocalQ do
   begin
     While NOT EOF Do
     Begin
       ShowMessage(FieldByName('Product_Model').AsString);
       Next;
     End;
   end;
 end;


TRObject Syntax
 Var
 LocalQ:TUniQuery;
 
 { 
   Clomosy.DBSQLServerConnect('SQL Server','server_name','user_name','user_password','database_name',1433);
   LocalQ = Clomosy.DBSQLServerQueryWith('SELECT model AS Product_Model FROM OperatingSystem');
   LocalQ.First;
   with LocalQ do
   {
     While (NOT EOF)
     {
       ShowMessage(FieldByName('Product_Model').AsString);
       Next;
     }
   }
 }