【发布时间】:2012-02-06 02:39:35
【问题描述】:
如果使用 VB.Net 和 OleDb 存在主键,我想检查 Access 数据库:
按主键名
按字段数作为主键
【问题讨论】:
标签: vb.net ms-access primary-key constraints
如果使用 VB.Net 和 OleDb 存在主键,我想检查 Access 数据库:
按主键名
按字段数作为主键
【问题讨论】:
标签: vb.net ms-access primary-key constraints
来自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
【讨论】: