我怎样在combox中,使它的item与数据库动态联系,下拉显示数据库中我要显示的东西?
如何通过点击一个命令按扭,进行数据库的备分,

解决方案 »

  1.   

    dbcombobox
    要不用query把记录取出来,add进你的combobox中用sql命令备份
    sqlserver中
    backup database 你的 to 备份
      

  2.   

    adoquery1.close;
        adoquery1.sql.Clear;
        adoquery1.sql.Add('select CCountry_name from T_Country');
        adoquery1.open;    Com_Country_name.Clear;
        adoquery1.first;
        while not adoquery1.eof do
        begin
          Com_Country_name.Items.Add(adoquery1.fieldbyname('CCountry_name').Value);
          adoquery1.Next;
        end;
      

  3.   

    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, ComCtrls, StdCtrls, DB, ADODB;type
      TForm1 = class(TForm)
        Button1: TButton;
        a1: TAnimate;
        Button2: TButton;
        edit_path: TEdit;
        ADOConnection1: TADOConnection;
        ADOCommand1: TADOCommand;
        OpenDialog1: TOpenDialog;
        procedure Button1Click(Sender: TObject);
        procedure Button2Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
    begin
        self.Caption := '正在备份数据....';
        a1.Active:=true;//a1是Tanimate控件用来显示传递的过程
       ADOCommand1.CommandText:='backup database d to disk='''+edit_path.Text
          +'''';//备份数据库命令语句,travel是sql2000的库名
      try
        ADOCommand1.Execute; // 执行备份
        showmessage('      备份成功!');
        a1.Active := false;
      except
        showmessage('      备份失败!');
        a1.Active := false;
      end;
      self.Caption := '数据备份和恢复';
    end;
    procedure TForm1.Button2Click(Sender: TObject);
    var
      DataPath: string;
    begin
    self.Caption := '正在恢复数据....';
      ADOConnection1.Close;//sk是我的模板,adoconnect是ADOConnection1控件
      ADOConnection1.Connected:=false;
      OpenDialog1.Filter := '备份文件 (*.back)|*.back|所有文件 (*.*)|*.*';
      //设置备份文件后缀,记得添加一个opendialog1控件
      OpenDialog1.InitialDir := ExtractFileDir(Application.ExeName) + '\backupdata';
      //设置备份路径
      if OpenDialog1.Execute then
        DataPath := OpenDialog1.FileName;
      if DataPath <> '' then
      begin
        if
          application.MessageBox('此操作将使上次备份以来的所有数据丢失,是否继续?',
          '恢复数据', MB_OKCANCEL) = idOK then
        begin
          a1.Active := true;
          ADOCommand1.CommandText:= 'restore database travel1 from disk=''' + DataPath
            + '''' + ' with replace'; //恢复数据命令语句,主要是这一句,记的yy是你的库
         //名
          try
            try
              ADOCommand1.Execute; //执行恢复过程
              showmessage('    恢复成功!');
            except
              showmessage('数据库正在被使用!请确定已关闭其它使用该数据库程序!');
              showmessage('    恢复失败!');
            end;
          finally
            a1.Active := false;
            try // 打开各个数据表是否有错误        except
              showmessage('程序运行发生不可预知错误,请重新启动程序!');
              //结束该程序
              Application.Terminate;
            end;
          end;
        end;
      end;
      self.Caption := '数据备份和恢复';end;end.
      

  4.   

    怎么还是实现不了啊?combobox运行时还是没有和数据库连啊?
      

  5.   

    用 DBLookupComboBox1 吧在listSource 里选择数据源在listField 里选择字段在keyField 里选择 同listfield一样的字段