【问题标题】:VB.Net - How can I check if a primary key exists in an Access DBVB.Net - 如何检查 Access DB 中是否存在主键
【发布时间】:2012-02-06 02:39:35
【问题描述】:

如果使用 VB.Net 和 OleDb 存在主键,我想检查 Access 数据库:

  • 按主键名

  • 按字段数作为主键

【问题讨论】:

    标签: vb.net ms-access primary-key constraints


    【解决方案1】:

    来自here

    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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-01-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多