插入SQL - 记录被写入两次

时间:2014-04-22 16:20:25

标签: sql-server vba ms-access-2010

我有一个Access 2010前端程序和一个SQL Server数据库作为后端 我编写了一个将记录插入SQL Server的例程。

以下是代码:

DoCmd.RunSQL "INSERT INTO [dbo_phoneno] (dtstamp, who, what,  sortorder, company, typephoneno, name, wphone, cphone, mob) " _
   & "VALUES(" _
   & "'" & pubDTStamp & "'," _
   & "'" & pubWho & "'," _
   & "'" & pubWhat & "'," _
   & "'" & pubSortOrder & "'," _
   & "'" & pubCompany & "'," _
   & "'" & pubType & "'," _
   & "'" & pubName & "'," _
   & "'" & pubWphone & "'," _
   & "'" & pubCphone & "'," _
   & "'" & pubMob & "') "

代码工作正常,除非我退出程序时再次写出记录。我检查了代码,但没看到它可以在哪里。有没有人有建议?

1 个答案:

答案 0 :(得分:0)

要么你的代码被执行两次,要么你有一个触发器来执行额外的INSERT

使用Sql Profiler并运行跟踪。您可以找到第二个INSERT来自哪里。如果它不是来自触发器,那么您必须在应用程序中设置断点并在调试模式下运行它。