在末进行查询前是用TABLE进行操作的,即单击DBGRID的每行信息时,则对应的控件显示这条记录的信息,代码如下:
procedure TForm1.DBGrRecordCellClick(Column: TColumn);
begin
    //ShowMessage('你点击的信息为--'+Column.Field.AsString);    //两种实现方法--1
    //ShowMessage('你点击的信息为--'+DBGrRecord.SelectedField.AsString);     //两种实现方法--2
       ComboBCompany.Text:=ADOTable.FieldValues['公司名称'];
       ComboBProductType.Text:=ADOTable.FieldValues['产品类型'];
       ComboBMaintainType.Text:=ADOTable.FieldValues['维修类型'];
       DateTimePickerIN.Date:=ADOTable.FieldValues['入仓日期'];
       DateTimePickerOUT.Date:=ADOTable.FieldValues['出仓日期'];
       SpEAmoutNum.Value:=ADOTable.FieldValues['数量'];
       ComboBUnits.Text:=ADOTable.FieldValues['单位'];
       if (ADOTable.FieldByName('维修情况').AsString='') or (ADOTable.FieldByName('备注').AsString='') then
         begin
          MemoTroubleDepict.Text:='';
          EditRe.Text:='';
         end
       else
         begin
          MemoTroubleDepict.Text:=ADOTable.FieldValues['维修情况'];
          EditRe.Text:=ADOTable.FieldValues['备注'];
       end;
end;
进行查询之后,再单击,则相应的控件则不能显示你所单击每条记录的信息,查询后的代码如下:
procedure TForm1.BitBtnFindClick(Sender: TObject);
begin
    ADOQueryFind.ConnectionString:='Provider=Microsoft.Jet.OLEDB.4.0;Data Source=.\maintain.mdb;Persist Security Info=False';
    with ADOQueryFind do
       begin
          close;
          sql.Clear;
          sql.Add('select * from MaintainTable where 公司名称=:Company or 产品类型=:ProductType');
          //sql.Add('and 产品类型=:ProductsType');
          parameters.ParamByName('Company').Value:=trim(ComboBoxCompany.Text);
          parameters.ParamByName('ProductType').Value:=trim(ComboBoxProductsType.Text);
          open;
       end;
   DataSource1.DataSet:=ADOQueryFind;
   DBGrRecord.DataSource:=DataSource1;
end;

解决方案 »

  1.   


                  ComboBCompany.Text:=ADOTable.FieldValues['公司名称']; 
                  ComboBProductType.Text:=ADOTable.FieldValues['产品类型']; 
                  ComboBMaintainType.Text:=ADOTable.FieldValues['维修类型']; 
                  DateTimePickerIN.Date:=ADOTable.FieldValues['入仓日期']; 
                  DateTimePickerOUT.Date:=ADOTable.FieldValues['出仓日期']; 
                  SpEAmoutNum.Value:=ADOTable.FieldValues['数量']; 
                  ComboBUnits.Text:=ADOTable.FieldValues['单位']; 改成
                    ComboBCompany.Text:=DataSource1.DataSet.FieldValues['公司名称']; 
                  ComboBProductType.Text:=DataSource1.DataSet.FieldValues['产品类型']; 
                  ComboBMaintainType.Text:=DataSource1.DataSet.FieldValues['维修类型']; 
                  DateTimePickerIN.Date:=DataSource1.DataSet.FieldValues['入仓日期']; 
                  DateTimePickerOUT.Date:=DataSource1.DataSet.FieldValues['出仓日期']; 
                  SpEAmoutNum.Value:=DataSource1.DataSet.FieldValues['数量']; 
                  ComboBUnits.Text:=DataSource1.DataSet.FieldValues['单位']; 
    就可以了。