访问QueryDef未更新链接表



设置:

我正在使用链接到MS访问文件的SQL Server数据库,以便我可以使用访问表单。

我正在使用自定义查询的未绑定表格,因为我正在处理几个表(如果有更有效的方法,我全力以赴(。

在SQL Server中,我已经设置了具有表格的数据库角色,我已经仔细检查了该角色可以更新表。

问题:

每当我使用querydef访问中的更新查询(如下所示(时,它将成功运行,但实际上并未更新表。

详细信息:

我也对插入查询遇到了问题,但这仅仅是因为我没有在数据库中添加的新列更新查询。我还确保我在更新查询中也做了同样的事情。

此外,我知道更新查询有效,因为我能够直接从SSMS更新该条目。

由于这似乎类似于我在这里发现的另一个访问/SQL服务器问题。我确保尝试使用该解决方案,然后刷新表链接。但是,这没有区别。

代码:

查询:

UPDATE con_people 
SET people_first_name = @firstName,
    people_last_name = @lastName,
    people_title = @title,
    people_group = @group,
    people_email = @email,
    people_shift = @shift,
    people_hiredate = @hireDate,
    people_location = @location,
    people_reportsTo = @reportsTo,
    people_versionCount = people_versionCount + 1,
    people_datelastupdated = @dateUpdated,
    people_isActive = @isActive
WHERE people_employeeID = @empID;

querydef:

Public Function UpdatePeople(firstName As String, _
                                lastName As String, _
                                title As Integer, _
                                group As Integer, _
                                Email As Variant, _
                                isActive As Boolean, _
                                Shift As Integer, _
                                Location As Integer, _
                                HireDate As Variant, _
                                ReportsTo As Variant, _
                                employeeID As Integer)
    OtherFunctions.Initialize
    Dim QDF As DAO.QueryDef
    If FindQuery("UpdatePeople") = True Then OtherFunctions.dbs.QueryDefs.Delete "UpdatePeople"
    Set QDF = OtherFunctions.dbs.CreateQueryDef("UpdatePeople", SQLUpdatePeople)
    QDF.Parameters("@firstName").Value = firstName
    QDF.Parameters("@lastName").Value = lastName
    QDF.Parameters("@title").Value = title
    QDF.Parameters("@group").Value = group
    QDF.Parameters("@email").Value = Email
    QDF.Parameters("@isActive").Value = isActive
    QDF.Parameters("@empID").Value = employeeID
    QDF.Parameters("@shift").Value = Shift
    QDF.Parameters("@hireDate").Value = HireDate
    QDF.Parameters("@location").Value = Location
    QDF.Parameters("@reportsTo").Value = ReportsTo
    QDF.Parameters("@dateUpdated").Value = ConvertTimeUnix.ConvertDateToUnix(Now())
    QDF.Execute
    If FindQuery("UpdatePeople") = True Then OtherFunctions.dbs.QueryDefs.Delete "UpdatePeople"
End Function

任何帮助都将受到赞赏,

谢谢。

感谢 @andre的评论,我能够找到问题的来源。

我在更新条目时使用了错误的数据类型。当我提供布尔值(SQL-Server位(时


有关解决方案的详细信息:

Andre提供的链接:错误对象 - 数据访问对象,并用MS -access确定ODBC失败的实际原因(错误3146(?有关dao.error对象的更多信息,请参考这些信息。

这是如何使用它的示例:

    Dim myerror As DAO.Error
    For Each myerror In DBEngine.Errors
        With myerror
            If .Number <> 3146 Then 'prevents the system from returning the basic error.
                MsgBox "Error #:" & .Number & ", Description: " & .Description & ", Source: " & .Source
            End If
        End With
    Next

一旦我运行它,就可以返回,允许我找到根本原因:


错误#:547,

描述:[Microsoft] [ODBC SQL Server驱动程序] [SQL Server]更新语句与外键约束" FK_PEOPLE_ISACTIVE"冲突。冲突发生在数据库"连续improvement",表" dbo.con_isactive",列'isactive_id'。,

来源:odbc.querydef

再次感谢Andre。

最新更新