Tweet RSS

Example Delphi Field by Name:

Div
Hello SyntaxHighlighter
Procedure change(TSQL: String);
begin
 With FrmFriends do
  begin
    MyDB.Close;
    MyDB.SQL.Text:= TSQL;
    MyDB.ExecSQL;
  end;
end;

Function Query(TSQL: String): String;
Var
  temp: String;
begin
  temp:='';
  With FrmFriends do  //Group statments so object applies to all OR could use FrmFriends.MyDB.
  begin
    Change(TSQL);  //Essential before a new SQL statement is used. Closes the DataSet
    MyDb.Open;  //Open DataSet so you can use it.
    MyDb.First; //Internal pointer set to first dataset.
    While not MyDB.EOF do //EOF -End of File.
    Begin //Extracting each field, by heading.
      Temp:= Temp+MyDB.FieldByName('Name').AsString+#9; //The exact field name as in the DB
      Temp:= Temp+MyDB.FieldByName('Surname').AsString+#9;
      Temp:= Temp+MyDB.FieldByName('Class').AsString+#9;
      Temp:= Temp+MyDB.FieldByName('CellNumber').AsString+#13;
      MyDB.Next //Moves pointer on.
    End;
  end;
  Result:= temp;
end;
Div

This is where you can find the TADOQuery component.

 Linking Databases to Delphi:

<< Previous Tutorial

>> Next Tutorial

Div

Current Tutorial:

</> Download Source Code

Current Tutorial Info:

This specific example of code uses a ADO Query component. This mean the connection string (OpenDB) procedure (Covered in the next tutorial), is not necessary here. 

myDB is the ADO component name.

When using an ADO component to create the string connection. Find <ConnectionString> under <Database> in the ADO Components properties. Click connection string, <Use Connection String>, Build, Select <MS Jet 4.0 OLE DB Provider>,  Click next, browse for you DB.