如何利用delphi7.0与SQL server进行库连接及对库的操作!最好有个小程序供小弟学习!请各位高手帮忙!小弟一定给分!

解决方案 »

  1.   

    //或者在adoQuery的object inspector的connectionString中按提示进行设置
    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, DB, ADODB, Grids, DBGrids, StdCtrls;type
      TForm1 = class(TForm)
        DataSource1: TDataSource;
        DBGrid1: TDBGrid;
        ADOQuery1: TADOQuery;
        Button1: TButton;
        Button2: TButton;
        procedure FormCreate(Sender: TObject);
        procedure Button1Click(Sender: TObject);
        procedure Button2Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.dfm}procedure TForm1.FormCreate(Sender: TObject);
    begin
      adoQuery1.ConnectionString :='Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=test;Data Source=GLINK';
    //test是数据库名称,glink是服务器名称。end;procedure TForm1.Button1Click(Sender: TObject);
    begin
      with adoQuery1 do begin
        close;
        sql.Clear ;           
        sql.add('select 日期,人员,项目,具体项目,金额 from out');
        sql.add('group by 日期,人员,项目,具体项目,金额');
        open;
      end;
    end;procedure TForm1.Button2Click(Sender: TObject);
    begin
      with adoQuery1 do begin
        close;
        sql.Clear ;
        sql.add('select 日期,人员,项目,具体项目,金额 from out');
        sql.Add('order by 日期,人员,项目,具体项目,金额');     
        open;
      end;
    end;end.
      

  2.   

    楼主都贴了两贴了啊
    就是ADOQuery 用他的 connectionString属性
    楼上的代码也有说明了