delphi中ado各个对象都是以控件形式出现,能否象vb中定义变量一样定义ado中的各个对象,能的话怎样定义

解决方案 »

  1.   

    可以
    uses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls, DB, ADODB;
    ...
    ...
    procedure TForm1.Button1Click(Sender: TObject);
    var aa:TADODataSet;
    begin
      aa:=Tadodataset.Create(self);
      aa.CommandText:='select * from worker';
      aa.Open;
    ...
    ...
      aa.Free;
    end;
      

  2.   

    u_Conn:_Connection;               //数据库连接(客户端游标)
        u_Comm:_Command;procedure TfrmAdo.btnConeectClick(Sender: TObject);
    var UserID,Password:WideString;
    begin
        screen.Cursor:=crHourGlass;
        sConn:='Provider=SQLOLEDB.1;'+
               'Persist Security Info=False;'+
               'OLE DB Services=-2;Auto Translate=true;'+
               'Application Name=qqqq;';
        sConn:=sConn+'Initial Catalog='+trim(leDataBase.Text)+';';            //数据库名
        sConn:=sConn+'Data Source='+trim(leServerName.Text);                   //服务器名
        UserID:=trim(leUser.Text);
        Password:=trim(lePassWord.Text);    try
          u_Conn.Open(sConn,UserID,Password,adConnectUnspecified);
          leInfo.Text:='连接成功';
          leInfo.Font.Color:=clGreen;
        except
          //u_Conn.Close;
          u_Conn:=nil;
          leInfo.Text:='连接失败';
          leInfo.Font.Color:=clRed;
        end;
        screen.Cursor:=crArrow;end;
      

  3.   

    procedure TfrmAdo.FormCreate(Sender: TObject);
    begin
      u_Conn:=nil;
      cdsDebt :=TClientDataSet.Create(nil);
      u_Conn  :=CoConnection.Create;
      u_Comm:=CoCommand.Create;end;