【问题标题】:What is the name of the violating unique index constraint in dao / ms-accessdao / ms-access中违反唯一索引约束的名称是什么
【发布时间】:2009-10-30 10:35:17
【问题描述】:

我正在尝试使用 DAO(在 MS-Access 中)将记录插入到表中,这样做时收到错误 3022(表示违反了唯一索引)。错误是正确的,因为实际上尝试插入的记录具有在表中已经找到的值。

现在,我想找出违反的唯一索引的名称。有人知道我是怎么得到这个的吗?

感谢您的任何指点 勒内

【问题讨论】:

  • 我不相信可以获得该信息,因为 DAO 错误对象不会返回被违反的确切约束/索引(至少,据我所知)。我确切地知道你正在经历什么,因为我有插入抛出错误,然后我不得不手动找出导致问题的列。
  • 感谢大卫证实了我的怀疑。至少我知道其他人和我有同样的问题。

标签: ms-access dao


【解决方案1】:

以下是一些注意事项:

Sub WithADO()
''Reference: Microsoft ADO Ext x.x For DLL and Security
Dim catTables As ADOX.Catalog
Dim cn As ADODB.Connection
Dim ndx As Object

Set catTables = CreateObject("ADOX.Catalog")

Set cn = CreateObject("ADODB.Connection")
dbfile = "C:\Docs\LTD.mdb"

    cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
              "Data Source=" & dbfile & ";"

Set catTables.ActiveConnection = cn

For Each ndx In catTables.Tables("Table1").Indexes
    strlist = ndx.Name & " " & ndx.Properties("Primary Key") & vbCrLf & strlist
Next
MsgBox strlist

Set catTables = Nothing

End Sub

Sub WithDAO()
''Reference: Microsoft DAO x.x Object Library
Dim db As DAO.Database
Dim tdf As TableDef
Dim ndx As Object

Set db = CurrentDb
Set tdf = db.TableDefs("Table1")

For Each ndx In tdf.Indexes

    If ndx.Primary = True Then
        MsgBox ndx.Name
    End If
Next
End Sub

您也可以使用模式。

【讨论】:

    猜你喜欢
    • 2020-04-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-05-03
    • 2022-01-06
    • 2014-11-27
    • 2022-01-23
    • 1970-01-01
    相关资源
    最近更新 更多