dao/ms-access中违反唯一索引约束的名称是什么 [英] What is the name of the violating unique index constraint in dao / ms-access
本文介绍了dao/ms-access中违反唯一索引约束的名称是什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用DAO(在MS-Access中)将记录插入表中,并且这样做,我收到错误3022(表明违反了唯一索引).该错误是正确的,因为实际上尝试插入的记录具有在表中已经找到的值.
I am trying to insert a record into a table with DAO (within MS-Access) and doing so, I receive an Error 3022 (which indicates that a unique index is violated). The error is correct since in fact the tried-to-insert record has a value which is already found in the table.
现在,我想找出违反的唯一索引的名称.有人知道我怎么得到这个线索吗?
Now, I'd like to find out the name of the violated unique index. Does someone have a clue how I'd get this?
感谢任何指针 雷内(René)
Thanks for any pointer René
推荐答案
以下是一些注意事项:
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
您还可以使用架构.
这篇关于dao/ms-access中违反唯一索引约束的名称是什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文