如题,怎样编码判断一个dataset中是否包含指定的字段?

解决方案 »

  1.   

    var 
      rtn: boolean;for i:=0 to dataset.fieldcount -1 do
    begin
      if dataset.field[i].FieldName = 你给定的字段名 then
      begin
        rtn:= true;//存在
        exit;
      end;
    end;
    rtn:= false;//不存在
      

  2.   

    Searches for a specified field in the dataset.function FindField(const FieldName: string): TField;DescriptionCall FindField to determine if a specified field component exists in a dataset. FieldName is the name of the field for which to search. This name can be the the name of a simple field, the name of a subfield of an object field that has been qualified by the parent field’s name, or the name of an aggregated field. If FindField finds a field with a matching name, it returns the TField component for the specified field. Otherwise it returns nil.FindField is the same as the FieldByName method, except that it returns nil rather than raising an exception when the field is not found.
      

  3.   

    ADOConnection1.GetFieldNames(TableName, StringList);
    Find := StringList.IndexOf(YourFindFieldName) > 0 ;