Search code examples
c#ms-accessoledbjet

How to determine MS Access field size via OleDb


The existing application is in C#. During startup the application calls a virtual method to make changes to the database (for example a new revision may need to calculate a new field or something). An open OleDb connection is passed into the method.

I need to change a field width. The ALTER TABLE statement is working fine. But I would like to avoid executing the ALTER TABLE statement if the field is already the appropriate size. Is there a way to determine the size of an MS Access field using the same OleDb connection?


Solution

  • Not sure if I understand your question completely.
    But you could query the table for 0 rows (SELECT 1 FROM myTable WHERE 1= 0)

    And you could use recordet's field collection, refer to that field by name or index and use field's property like size, type etc.

    Does that help?