Vb.net 如何检查Access数据库中是否存在主键
我想使用VB.Net和OleDb检查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,
- 按主键名称
- 按字段数作为主键
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