Change Size and Type of field 
Author Message
 Change Size and Type of field

Hello everybody,

I use MS Access database in delphi 3.
How can I change the size (physical size of the field) and the type of a
field in the run-time?
Example 1:
    MyTable.Open;
    MyTable.Fields[0].Size;
I get an error "Can not in open database"
Example 2:
    MyTable.Close;
    MyTable.Fields[0].Size;
I get an error "List-index out of range"

Thanks,



Wed, 18 Jun 1902 08:00:00 GMT  
 Change Size and Type of field


Quote:
>I use MS Access database in Delphi 3.
>How can I change the size (physical size of the field) and the type of a
>field in the run-time?
>Example 1:
>    MyTable.Open;
>    MyTable.Fields[0].Size;
>I get an error "Can not in open database"
>Example 2:
>    MyTable.Close;
>    MyTable.Fields[0].Size;
>I get an error "List-index out of range"

Properties like Size use the existing metadata definitions of a table to
provide their information. They cannot, however, be used to alter metadata.
To do that in a Microsoft Access database, you would need to use SQL
statements executed from a TQuery.

Take a look at the ALTER TABLE statement. This statement allows you to add
or delete a column. But it does not allow you to change a column's
definition. Therefore, to do that you need multiple steps, storing the
existing data of the column in a temporary column while you delete the
original field and recreate it with a new definition. For copying data
between columns, look at the UPDATE statement.

To execute statements like these from a TQuery, use its ExecSQL method, not
its Open method or Active property (a very common mistake).

//////////////////////////////////////////////////////////////////////////
Steve Koterski                 "Like a camel, I can go without a drink for
Technical Publications         seven days--and have on several horrible
INPRISE Corporation            occasions."
http://www.borland.com/delphi                                 -- Herb Caen



Wed, 18 Jun 1902 08:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Change the Size and the Type of a Field

2. Changing Field Type with Fields Editor in D2

3. type and size of fields are gone in Data desktop

4. How to find ORACLE number type fields, size

5. Annoying behaviour when you change field sizes

6. Changing the size of database fields at runtime

7. How to change the type of a database field

8. Open a Table and then change a type of Field

9. Change data types of a field programmatically

10. Changing of a field type

11. Can't change type of field

12. Dynamic Filter on TCustomADODataset where filter field data type change

 

 
Powered by phpBB® Forum Software