How to find auto-increment indexes in access database

Marco Dell'Oca 181 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

Visual Studio
Visual Studio
A family of Microsoft suites of integrated development tools for building applications for Windows, the web and mobile devices.
5,193 questions
VB
VB
An object-oriented programming language developed by Microsoft that is implemented on the .NET Framework. Previously known as Visual Basic .NET.
2,737 questions
Access Development
Access Development
Access: A family of Microsoft relational database management systems designed for ease of use.Development: The process of researching, productizing, and refining new or existing technologies.
881 questions
{count} votes

Accepted answer
  1. Jiachen Li-MSFT 32,376 Reputation points Microsoft Vendor
    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.