建立:
我正在使用链接到MS Access文件的SQL Server数据库,因此我可以使用Access窗体。
我使用自定义查询的未绑定表单,因为我正在处理几个表(如果有一个更有效的方式我全部为它)。
在SQL Server中,我已经设置了一个具有表权限的数据库角色,我已经仔细检查过我已经允许角色更新表。
问题:
每当我使用QueryDef(如下所示)在Access中使用我的更新查询时,它都会成功运行,但实际上并不会更新表。
细节:
我的插入查询也遇到了问题,但这只是因为我没有使用我在数据库中添加的新列更新查询。我还确保我为更新查询做了同样的事情。
另外我知道更新查询有效,因为我能够直接从SSMS更新条目。
因为这看起来类似于我有的另一个访问/ sql-server问题,Found Here。我确保尝试解决该问题的解决方案,刷新表格链接。但是,它没有任何区别。
码:
查询:
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 BIT)时,SQL-Server期望一个INT(用于外键)。
详情关于解决方案:
友情链接:安德烈:Error Object - Data Access Object和Determine real cause of ODBC failure (error 3146) with ms-access?。有关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
一旦我运行它,就会返回,让我找到根本原因:
再次,谢谢安德烈。