Solved

VB.net Access Check if Primary Key column is an AutoNumber

Posted on 2013-06-25
3
631 Views
Last Modified: 2013-06-25
Hi
I use the following VB.net code to check if a column is a Primary key.
How do I check whether it is an AutoNumber column


 Public Function getKeyNames(tableName As String) As String
        Try


            Dim connection As New OleDbConnection(Globals.ThisAddIn.oRIGHT.lblConnectionString.Text)
            connection.Open()

            Dim mySchema As DataTable = TryCast(connection, OleDbConnection).GetOleDbSchemaTable(OleDbSchemaGuid.Primary_Keys, New [Object]() {Nothing, Nothing, tableName})


            ' following is a lengthy form of the number '3' :-)
            Dim columnOrdinalForName As Integer = mySchema.Columns("COLUMN_NAME").Ordinal

            For Each r As DataRow In mySchema.Rows
                'THIS GETS ALL THE KEYS IN THE TABLE -BUT I AM JUST USING THE FIRST ONE
                ''returnList.Add(r.ItemArray(columnOrdinalForName).ToString())
                getKeyNames = r.ItemArray(columnOrdinalForName).ToString()
                GoTo Jump 'Jump out after retrieving first one
            Next

Jump:
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try

    End Function
0
Comment
Question by:murbro
  • 2
3 Comments
 
LVL 42

Accepted Solution

by:
sedgwick earned 500 total points
ID: 39274098
0
 

Author Comment

by:murbro
ID: 39274654
Hi Sedgwick

Thanks for that but what SQL query or VB.net code would I use for that?
0
 

Author Closing Comment

by:murbro
ID: 39274958
Thanks
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

QuickBooks® has a great invoice interface that we were happy with for a while but that changed in 2001 through no fault of Intuit®. Our industry's unit names are dictated by RUS: the Rural Utilities Services division of USDA. Contracts contain un…
I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now