[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

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

Posted on 2013-06-25
3
Medium Priority
?
673 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:Murray Brown
  • 2
3 Comments
 
LVL 42

Accepted Solution

by:
Meir Rivkin earned 2000 total points
ID: 39274098
0
 

Author Comment

by:Murray Brown
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:Murray Brown
ID: 39274958
Thanks
0

Featured Post

 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
We live in a world of interfaces like the one in the title picture. VBA also allows to use interfaces which offers a lot of possibilities. This article describes how to use interfaces in VBA and how to work around their bugs.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Suggested Courses

825 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