简体   繁体   English

SQL 链接表可以插入不能删除运行时 3086

[英]SQL Linked Table Can Insert Can't Delete Run-Time 3086

I use Access VBA to add and remove records in a single SQL table, which contains 2 columns of varchar codes.我使用 Access VBA 在单个 SQL 表中添加和删除记录,该表包含 2 列varchar代码。 I am a dbowner on the SQL Server database.我是 SQL 服务器数据库的dbowner My code to add values to this table works:我向此表添加值的代码有效:

For Each varItm In Me.lstMyAllTypes.ItemsSelected
            AddSQL = "INSERT INTO xyzMyTable ([MyCode1],[MyCode2]) " & _
                     "VALUES ('" & Me.lstMyAllTypes.Column(0, varItm) & "','" & Me.cboType.Column(1) & "');"
            'EXECUTE SQL
            CurrentDb.Execute AddSQL, dbSeeChanges
            'Debug.Print AddSQL
Next varItm

My delete code throws a run-time error 3086:我的删除代码引发运行时错误 3086:

For Each varItm In Me.MylstTypes.ItemsSelected
    RemSQL = "DELETE FROM xyzMyTable " & _
              "WHERE xyzMyTable.MyCode1 = '" & Me.MylstTypes.Column(0, varItm) & _
              "' AND xyzMyTable.MyCode2 = '" & Me.cboType.Column(1) & "'"
            'EXECUTE SQL
            DoCmd.SetWarnings False
            CurrentDb.Execute RemSQL, dbSeeChanges
            DoCmd.SetWarnings True
Next varItm

I debug the delete SQL string and I can run it in SSMS, but not in Access.我调试删除 SQL 字符串,我可以在 SSMS 中运行它,但不能在 Access 中运行。 If I create the same delete query in an Access query, it does not work.如果我在 Access 查询中创建相同的删除查询,它将不起作用。 If I open the table, and try to delete the row, it makes a ding noise, but there is no pop-up error.如果我打开表格并尝试删除该行,它会发出叮当声,但没有弹出错误。 How can I add but not delete?如何添加但不删除?

This table has no relationships in SQL Server to any other tables, so referential integrity would not be an issue.此表在 SQL 服务器中与任何其他表没有关系,因此参照完整性不会成为问题。

To delete or update in a linked ODBC table, the table needs to have a Primary Key .要在链接的 ODBC 表中删除或更新,该表需要具有Primary Key

The PK must be recognized by Access: open the linked table in design view, check there is a "lock" icon in the PK column(s). Access 必须识别 PK:在设计视图中打开链接表,检查 PK 列中是否有“锁定”图标。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM