Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vb.net 如何检查Access数据库中是否存在主键_Vb.net_Ms Access_Primary Key_Constraints - Fatal编程技术网

Vb.net 如何检查Access数据库中是否存在主键

Vb.net 如何检查Access数据库中是否存在主键,vb.net,ms-access,primary-key,constraints,Vb.net,Ms Access,Primary Key,Constraints,我想使用VB.Net和OleDb检查Access数据库中是否存在主键: 按主键名称 按字段数作为主键 来自: 发件人: Public Shared Function getKeyNames(tableName As [String], conn As DbConnection) As List(Of String) Dim returnList = New List(Of String)() Dim mySchema As DataTable = TryCast(conn,

我想使用VB.Net和OleDb检查Access数据库中是否存在主键:

  • 按主键名称

  • 按字段数作为主键

来自:

发件人:

Public Shared Function getKeyNames(tableName As [String], conn As DbConnection) As List(Of String)
    Dim returnList = New List(Of String)()


    Dim mySchema As DataTable = TryCast(conn, 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
        returnList.Add(r.ItemArray(columnOrdinalForName).ToString())
    Next

    Return returnList
End Function