How to find auto-increment indexes in access database

Marco Dell'Oca 201 Reputation points
2024-07-24T15:39:31.19+00:00

From visual studio 2022 I need to find in an access database the list of indexes that have an automatic increase.

I tried with oledbconnection.getshema("indexes")

but I did not succeed.

Can anyone help me?

Thank you

Marco Dell'Oca

Microsoft 365 and Office | Access | Development
Developer technologies | VB
Developer technologies | Visual Studio | Other
{count} votes

Accepted answer
  1. Jiachen Li-MSFT 34,221 Reputation points Microsoft External Staff
    2024-07-25T06:27:57.8566667+00:00

    Hi @Marco Dell'Oca ,

    You can use OleDbConnection.GetSchema("Columns") to get the column details and then filter out the AutoNumber fields.

            Dim connectionString As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=YourDatabase.accdb;"
            Using connection As New OleDbConnection(connectionString)
                connection.Open()
                
                Dim columnsSchema As DataTable = connection.GetSchema("Columns")
    
                Dim autoNumberColumns = From row In columnsSchema.AsEnumerable()
                                        Where row.Field(Of String)("COLUMN_DATA_TYPE") = "3" AndAlso row.Field(Of Boolean)("AUTOINCREMENT") = True
                                        Select TableName = row.Field(Of String)("TABLE_NAME"), ColumnName = row.Field(Of String)("COLUMN_NAME")
    
                For Each column In autoNumberColumns
                    Console.WriteLine("Table: {0}, Column: {1}", column.TableName, column.ColumnName)
                Next
            End Using
    
    

    Best Regards.

    Jiachen Li


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment". Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.

5 additional answers

Sort by: Most helpful
  1. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more

  2. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more

  3. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more

  4. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.