Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2013-06-25
3
Medium Priority
?
669 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

Question has a verified solution.

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

It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
Code that checks the QuickBooks schema table for non-updateable fields and then disables those controls on a form so users don't try to update them.
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses

610 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