我想获取某个表的某个字段的数据类型,该怎么做?
adoquery1.Fields.Fields[1].DataType行的通吗?
如何把adoquery1.Fields.Fields[1].DataType的返回结果通过showmessage显示出来,类型怎么转?
谢谢,在线等待!

解决方案 »

  1.   

    adoquery1.Fields.Fields[1].DataType得到当前字段的数据类型是没有问题的
      

  2.   

    可是
    type TFieldType = (ftUnknown, ftString, ftSmallint, ftInteger, ftWord, ftBoolean, ftFloat, ftCurrency, ftBCD, ftDate, ftTime, ftDateTime, ftBytes, ftVarBytes, ftAutoInc, ftBlob, ftMemo, ftGraphic, ftFmtMemo, ftParadoxOle, ftDBaseOle, ftTypedBinary, ftCursor, ftFixedChar, ftWideString, ftLargeint, ftADT, ftArray, ftReference, ftDataSet, ftOraBlob, ftOraClob, ftVariant, ftInterface, ftIDispatch, ftGuid, ftTimeStamp, ftFMTBcd);这么多数据类型你区分起来就麻烦了,除非你可以肯定只有其中的几种,那就一一比较好了
      

  3.   

    请问怎么show出来,而且我的代码显示不对,明明是STRING类型,但是就是不认
    if adoquery1.Fields.Fields[1].DataType=ftstring then
       showmessage('1');
      

  4.   

    var
      Str : String;
    case adoquery1.Fields.Fields[1].DataType of 
      ftBoolean :Str := 'ftBoolean '
      ftBytes :Str := 'ftBoolean '
      ftBlob :Str := 'ftBoolean '
      ftMemo :Str := 'ftBoolean '
      ftGraphic:Str := 'ftBoolean '
    end;ShowMessage(Str)
      

  5.   

    转贴:
    请参考:
    procedure TForm1.Button1Click(Sender: TObject);
    var
      i: Integer;
      F: TFieldDef;
      D: String;
    begin
      Table1.Active := True;
      ListBox1.Items.Clear;
      with Table1 do begin
        for i := 0 to FieldDefs.Count - 1 do begin
          F := FieldDefs.Items[i];
          case F.DataType of
            ftUnknown: D := 'Unknown';
            ftString: D := 'String';
            ftSmallint: D := 'SmallInt';
            ftInteger: D := 'Integer';
            ftWord: D := 'Word';
            ftBoolean: D := 'Boolean';
            ftFloat: D := 'Float';
            ftCurrency: D := 'Currency';
            ftBCD: D := 'BCD';
            ftDate: D := 'Date';
            ftTime: D := 'Time';
            ftDateTime: D := 'DateTime';
            ftBytes: D := 'Bytes';
            ftVarBytes: D := '';
            ftBlob: D := 'BLOB';
            ftMemo: D := 'Memo';
            ftGraphic: D := 'Graphic';
          else
            D := '';
          end;
          ListBox1.Items.Add(F.Name + ', ' + D);
        end;
      end;
      Table1.Active := False;
    end;
      

  6.   

    问题解决了,谢谢hqhhh(枫叶)