getting field data types of a table 
Author Message
 getting field data types of a table

I need to get the field data types from a table. Here is an example of
what I am looking for : field name, field data type, field size. I can
get the field name and the field size but I am struggling to get the
field data type. What am I missing?

fieldname :=  Table1.Fields[i].FieldName;
fieldsize  := table1.FieldDefs.Find(thefieldname).size

thanks
gerald



Sun, 25 Jul 1999 03:00:00 GMT
 getting field data types of a table

Quote:

>I need to get the field data types from a table. Here is an example of
>what I am looking for : field name, field data type, field size. I can
>get the field name and the field size but I am struggling to get the
>field data type. What am I missing?

>fieldname :=  Table1.Fields[i].FieldName;
>fieldsize  := table1.FieldDefs.Find(thefieldname).size

Why not use FieldDefs instead of Fields?  FieldDefs has all the
information in one place.  Here's an example...

        var
           x : integer;
        begin
             Table1.Open;
             for x := 0 to Table1.FieldCount - 1 do
             with ListBox1.Items, Table1.FieldDefs[x] do
             begin
                 Add( Name + ' / ' +
                      IntToStr( Ord( DataType ) ) + ' / ' +
                      IntToStr( Size ) );
             end;

        end;

DataType returns a value of type TFieldType, so you'd have to write
some sort of function to return a string value of the type if you
wanted to display it that way.  Here's a sample:

        function FieldTypeAsString( Value : TFieldType ) : string;
        begin
             case Value of
                  ftUnknown : Result := 'Unknown';
                  ftString : Result := 'String';
                  ftSmallint : Result := 'SmallInt';
                  ftInteger : Result := 'Integer';
                  ftWord : Result := 'Word';
                  ftBoolean : Result := 'Boolean';
                  ftFloat : Result := 'Float';
                  ftCurrency : Result := 'Currency';
                  ftBCD : Result := 'BCD';
                  ftDate : Result := 'Date';
                  ftTime : Result := 'Time';
                  ftDateTime : Result := 'DateTime';
                  ftBytes : Result := 'Bytes';
                  ftVarBytes : Result := 'VarBytes';
                  ftAutoInc : Result := 'AutoInc';
                  ftBlob : Result := 'Blob';
                  ftMemo : Result := 'Memo';
                  ftGraphic : Result := 'Graphic';
                  ftFmtMemo : Result := 'FmtMemo';
                  ftParadoxOle : Result := 'Paradox-OLE';
                  ftDBaseOle : Result := 'dBASE-OLE';
                  ftTypedBinary : Result := 'TypedBinary';
             end;
        end;

Now you can rewrite the first example this way:

        var
           x : integer;
        begin
             Table1.Open;
             for x := 0 to Table1.FieldCount - 1 do
             with ListBox1.Items, Table1.FieldDefs[x] do
             begin
                 Add( Name + ' / ' +
                      FieldTypeAsString( DataType ) + ' / ' +
                      IntToStr( Size ) );
             end;

        end;



Mon, 26 Jul 1999 03:00:00 GMT
 getting field data types of a table



Quote:
> get the field name and the field size but I am struggling to get the
> field data type. What am I missing?

> fieldname :=  Table1.Fields[i].FieldName;
> fieldsize  := table1.FieldDefs.Find(thefieldname).size

fieldtype : TFieldType;
fieldtype := table1.FieldDefs.Find(thefieldname).DataType;

Is this what you mean?

//ns



Thu, 29 Jul 1999 03:00:00 GMT
 
 [ 3 post ] 

 Relevant Pages 

1. Data Type transparent to the type of the table field

2. Inserting Data into LONG data type field in an ORACLE Table

3. How can I change or edit field data type in an exsting table

4. Linked Server Table Field Data Type

5. SQL tables - Determine the data type of the fields

6. SQL table field data types

7. Money field type same as Currency data type??

8. insert data from one field in one table to another field in another table

9. Data Transfer from Long data type to SQL Server Text data type column

10. Getting the correct type of a field

11. Table type with user defined data type.

12. Newbie question:Getting field Type?


 
Powered by phpBB® Forum Software