Solved

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

Posted on 2013-06-25
3
644 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

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

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

This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…

777 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