IDbTableManager..::.GetPrimaryKey Method Home
.NET Framework Class Library
IDbTableManager..::.GetPrimaryKey Method

Returns a list of primary keys for the specified table.

Namespace:  Microsoft.Web.Management.DatabaseManager
Assembly:  Microsoft.Web.Management.DatabaseManager (in Microsoft.Web.Management.DatabaseManager.dll)
Syntax

'Usage

Dim instance As IDbTableManager
Dim connectionString As String
Dim tableName As String
Dim schema As String
Dim returnValue As String()

returnValue = instance.GetPrimaryKey(connectionString, _
    tableName, schema)

'Declaration

Function GetPrimaryKey ( _
    connectionString As String, _
    tableName As String, _
    schema As String _
) As String()

Parameters

connectionString
Type: System..::.String
The connection string for the database.
tableName
Type: System..::.String
The name of the table.
schema
Type: System..::.String
The schema name for the table.
NoteNote:

If schema is empty, the default schema name will be used.

Return Value

Type: array<System..::.String>[]()[]
The array of primary keys.
Remarks

All database providers that implement the IDbTableManager interface must also implement the GetPrimaryKey method, which the database manager will use to retrieve an array of primary keys from a database.

Notes for Implementers

If your provider does not support retrieving the list of primary keys, you can use the following code sample to raise a not-implemented exception:

public string[] GetPrimaryKey(string connectionString, string tableName, string schema)
{
   throw new NotImplementedException();
}
Examples

The following code sample shows how to use the GetPrimaryKey method to retrieve the list of primary keys for an OLEDB connection by using the table name that the database manager provides.


    Public Function GetPrimaryKey( _
            ByVal connectionString As String, _
            ByVal tableName As String, _
            ByVal schema As String) As String() _
            Implements Microsoft.Web.Management.DatabaseManager.IDbTableManager.GetPrimaryKey

        Dim restrictions() As String = New String() {Nothing, Nothing, tableName}
        Dim dataTable As DataTable
        Dim primaryKeys As List(Of String) = New List(Of String)
        ' Create a connection to the database.
        Dim connection As OleDbConnection = New OleDbConnection(connectionString)
        connection.Open()
        ' Open the schema information for the primary keys.
        dataTable = connection.GetOleDbSchemaTable(OleDbSchemaGuid.Primary_Keys, restrictions)
        ' Enumerate the table's primary keys.
        For Each row As DataRow In dataTable.Rows
            ' Append each primary key to the list.
            primaryKeys.Add(row("COLUMN_NAME").ToString)
        Next
        ' Return the list of primary keys.
        Return primaryKeys.ToArray

    End Function



Permissions

  • Full trust for the immediate caller. This member cannot be used by partially trusted code. For more information, see .
See Also

Reference

© 2009 Microsoft Corporation. All rights reserved.   Terms of Use | Trademarks | Privacy Statement
Page view tracker
Rate the Lightweight library
x
Lightweight builds on ScriptFree (loband) by adding features you've requested: a SearchBox and default code language selection.
Do you like the SearchBox?
Do you like the tabbed code blocks?
How useful is this topic?
Tell us more.
Thanks
x
You're helping to improve MSDN Online.
Feedback
Switch View
Classic
Lightweight Beta
ScriptFree
Switch View