How to request Primary Keys from OLE DB Table

Hi,

i want to request Primary Keys from an OLE DB Tables. This works fine if my table has only one Primary Key. However, if the primary key is an composite key, the following function will only return true if the first part of the composite key is requested.

Any ideas to fix this problem Or to request all Primary Keys at once

Thanks,

Stefan

public Boolean isPrimary(int checkPos, String tableName)

{

DataTable mySchema = getConnectionPtr().GetOleDbSchemaTable(OleDbSchemaGuid.Primary_Keys, new Object[] {null, null, tableName});

return (mySchema.Rows[0].ItemArray[3].ToString() == (String) getColumNames()[checkPos]);

}



Answer this question

How to request Primary Keys from OLE DB Table

  • wdudek

    Hi, we're working on Paradox and MS SQL Databases. I'm refering to the columns of which the primary key is composed.
  • Liam .net

    The following works fine for me (lists all column names in the primary key):

    Dim DatabaseConnection As New System.Data.OleDb.OleDbConnection

    Dim SchemaTable As DataTable

    DatabaseConnection.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _

    "Data Source=C:\Test Files\db1 XP.mdb"

    DatabaseConnection.Open()

    SchemaTable = DatabaseConnection.GetOleDbSchemaTable(System.Data.OleDb.OleDbSchemaGuid.Primary_Keys, _

    New Object() {Nothing, Nothing, "TestKeyTable"})

    Dim RowCount As Int32

    For RowCount = 0 To SchemaTable.Rows.Count - 1

    Console.WriteLine(SchemaTable.Rows(RowCount)!COLUMN_NAME.ToString)

    Next RowCount

    DatabaseConnection.Close()



  • Rizzlers

    Hi,is working for one primary key as descriped in newsgroup. Not working for composed Primary Key.
  • StephanieR


    Is this working for you now I noticed your post in the Microsoft NNTP newsgroup microsoft.public.dotnet.framework.adonet.

  • Lawrence Kok

    Thanks. Helps a lot.
  • Shirvo


    What type of database are you working with Are you referring to the columns of which the primary key is comprised

  • How to request Primary Keys from OLE DB Table