Board index » delphi » ADO without controls

ADO without controls

Hi everybody,

is there a way to access a database using ADO without having any ADO
controls on a form? Where can I find sample code?

Timo

 

Re:ADO without controls


All ADOExpress components are not visible. You won't see any data as long as
you don't use controls from the Data Controls tab.
You can get data from ADOExpress components by using methods and properties.

Example:

var
  Extension: String;
begin
  ADODataSet1.Open;
  try
    if ADODataSet1.Locate('UserName', 'Addams', []) then
      Extension := ADODataSet1.FieldByName('Extension').AsString
    else
      Extension := 'Unknown';
  finally
    ADODataSet1.Close;
  end;
end;

"Timo Gransch" <timo.gran...@epost.de> schreef in bericht
news:15733041.0107100103.2eb17e11@posting.google.com...

Quote
> Hi everybody,

> is there a way to access a database using ADO without having any ADO
> controls on a form? Where can I find sample code?

> Timo

Re:ADO without controls


Hello, "Timo Gransch" <timo.gran...@epost.de>! You wrote:

Quote
> is there a way to access a database using ADO without having any ADO
> controls on a form? Where can I find sample code?

Use ADOInt.pas unit. There you'll find out  wrappers for ADO's interfaces.
Sample code... it would be like this:

var
 rs: Recordset;
 cn: OleVariant;
begin
 cn := CoConnection.Create;
 rs := CoRecordset.Create;
 try
  cn.Open('Provider=MSSQL; ....', 'UserName', 'Password', adNotSpecified);
  rs.Open('SELECT ...', cn, adOpenKeyset, adLockBatchOptimistic, adCmdText);

  /*Do all that necessary with recordset*/

 finally
  rs.Close;
  cn.Close;
  rs.Free;
  cn.Free;
 end;
end;

 Code above I invented "on fly" but it's about to be working. The best
example of how to use ADO interfaces you will see at the ADODB.pas unit.

PS. Why don't you want to use ADO components which have very little
overheading?

--
    Evgeny V. Levashov, software developer,
    ICQ UIN 34864288
    Mebel Massiv Co, Tula, Russia
    http://home.tula.net/mebelmassiv

Other Threads