我有个table,2列,通过databridge,Dcom,dataset,datasource显示在DBGridEh中现在我想通过按钮触发lookup,把lookup的结果显示在DBGridEh中
CDSTable.Data := CDSTable.Lookup('CONTENT',Edit1.Text,'ITEMNAME;CONTENT');上面的代码报错invalid data packet
为什么 

解决方案 »

  1.   

    Lookup 返回的是Variant类型数据,与CDS的Data所需类型不同。
      

  2.   

    请参照下列DELPHI帮助:
    This example shows how to use the OnDataRequest event to allow a client application to pass a filter expression to the provider and then receive only the records matching the filter. 
    The OnDataRequest event handler of the provider looks like the following:function TForm1.Provider1DataRequest(Sender: TObject; Input: OleVariant): OleVariant;begin
      with (Sender as TDataSetProvider) do
      begin
        DataSet.Filter := Input;
        DataSet.Filtered := True;
        DataSet.First;
        Result := Data;
      end;end;On the client side, the DataRequest method can be used to fetch the data.  The DataRequest method triggers an OnDataRequest event in the Provider component and returns the result of the event handler:procedure TForm1.Button1Click(Sender: TObject);begin
      ClientDataSet1.Data := ClientDataSet1.DataRequest(FilterEdit.Text);
    end;
      

  3.   


    你这个例子是OnDataRequest 啊现在我想把lookup的数据显示出来怎么搞呢
      

  4.   

    返回的是Variant类型,可以用循环将其显示出来。如:
    var
      DataRecord : Variant;
      i :integer;
    begin
      DataRecord := CDS.Lookup(...);
      for i := Low(DataRecord) to High(DataRecord) do
         showmessage(DataRecord[i]);
    end;
      

  5.   


    不是showmessage阿是在DBGrideEh中
      

  6.   

    KeyFields           qtemp表中的关联字段名
    LookupDataSet       查找数据集
    LookupKeyFields     数据集中的关联字段名
    LookupResultField   数据集中的返回字段名
      

  7.   

    function   Lookup(const   KeyFields:   String;   const   KeyValues:   Variant;   const   ResultFields:   String):   Variant;   override;   
      第一个参数为:要搜索的字段,可以有多个,中间以分号分隔   
      第二个参数为:搜索的值,如果为多个的时候,需要创建Veriant数组   
      第三个参数为:要返回的字段   
        
      举例:   
      Dataset1.lookup('no,name',VarArrayOf('01','duanhai'),'from')第一个参数为:要搜索的字段,可以有多个,中间以分号分隔   
      第二个参数为:搜索的值,如果为多个的时候,需要创建Veriant数组   
      第三个参数为:要返回的字段 例子:procedure Tcfrm_login.BitBtn1Click(Sender: TObject);
    var
      kl:variant;
      pass:string;
    begin
      username:=Combobox1.text;
      kl:=dm.ado_user.lookup('username',username,'pass');//第一个为要搜索的字段,第二个是在搜索的值,第三个是返回的值
      if varisnull(kl) then pass:='' else pass:=kl;
      if edit1.text<>pass then
         begin
           i:=i+1;
           if i>=3 then
            begin
            Application.MessageBox(PChar('密码验证错误,拒绝访问!'), PChar('提示'),
            MB_ICONEXCLAMATION);
            Application.Terminate;
            close;
            end;
           application.messagebox(pchar('密码验证错误,重新录入!'),pchar('提示'),
           MB_ICONQUESTION);
           edit1.text:='';
           edit1.SetFocus();
           exit;
         end;
      dm.ADO_user.Close;
      cfrm_login.hide;
      cfrm_mainform:=tcfrm_mainform.create(application);
      cfrm_mainform.showmodal;
    end;