gpt4 book ai didi

sql - 记录集类型不匹配问题

转载 作者:行者123 更新时间:2023-12-02 21:29:30 24 4
gpt4 key购买 nike

我正处于该项目的尾声,通过 ADO 连接进行下载给了我一些最后的减速带。我不断收到类型不匹配错误

Set targetrs = CurrentDb.OpenRecordset("tblEmpData", dbOpenTable)

整个代码是:

Public Sub DownloadData()

Dim targetrs As New ADODB.Recordset

Set targetrs = CurrentDb.OpenRecordset("tblEmpData", dbOpenTable)

Dim Con As New ADODB.Connection
Dim sqlStr As String
Con.Open _
"Provider = sqloledb;" & _
"Data Source=SERVER;" & _
"Initial Catalog=CAT;" & _
"User ID=ID;" & _
"Password=PW;"

Dim rsSource As New ADODB.Recordset

rsSource.Open "SELECT dbo.TMS_employee_HR.Region AS REG_NR, dbo.TMS_employee_HR.District AS DIS_NR, dbo.TMS_employee_HR.GEMSID, dbo.TMS_employee_HR.TMS_ID," & _
" dbo.TMS_employee_HR.Last_Name + ', ' + dbo.TMS_employee_HR.First_Name AS EMP_NA, dbo.TMS_employee_HR.Gender AS EMP_SEX_TYP_CD," & _
" dbo.TMS_employee_HR.EEOC AS EMP_EOC_GRP_TYP_CD, dbo.TMS_employee_HR.Division AS DIV_NR, dbo.TMS_employee_HR.Center AS CTR_NR," & _
" dbo.TMS_employee_HR.Job_Title AS JOB_CLS_CD_DSC_TE, dbo.TMS_employee_HR.Job_Group_Code AS JOB_GRP_CD, dbo.TMS_employee_HR.Job_Function," & _
" dbo.TMS_employee_HR.Job_Group, dbo.TMS_Data_Latest_Career_Meeting_Rating.Meeting_Readiness_Rating," & _
" dbo.TMS_Data_Latest_Career_Meeting_Rating.Manager_Readiness_Rating" & _
" FROM dbo.TMS_Data_Latest_Career_Meeting_Rating RIGHT OUTER JOIN" & _
" dbo.TMS_employee_HR ON dbo.TMS_Data_Latest_Career_Meeting_Rating.Employee_ID = dbo.TMS_employee_HR.TMS_ID" & _
" WHERE (dbo.TMS_employee_HR.Employment_Status = 'Active') AND (dbo.TMS_Data_Latest_Career_Meeting_Rating.Meeting_Year = '2013') OR" & _
" (dbo.TMS_Data_Latest_Career_Meeting_Rating.Employee_ID IS NULL)" & _
" GROUP BY dbo.TMS_employee_HR.Region, dbo.TMS_employee_HR.District, dbo.TMS_employee_HR.GEMSID, dbo.TMS_employee_HR.TMS_ID," & _
" dbo.TMS_employee_HR.Gender, dbo.TMS_employee_HR.Last_Name + ', ' + dbo.TMS_employee_HR.First_Name, dbo.TMS_employee_HR.EEOC," & _
" dbo.TMS_employee_HR.Division, dbo.TMS_employee_HR.Center, dbo.TMS_employee_HR.Job_Title, dbo.TMS_employee_HR.Job_Group_Code," & _
" dbo.TMS_employee_HR.Job_Function, dbo.TMS_employee_HR.Job_Group, dbo.TMS_Data_Latest_Career_Meeting_Rating.Meeting_Readiness_Rating," & _
" dbo.TMS_Data_Latest_Career_Meeting_Rating.Manager_Readiness_Rating; ", Con

Do Until rsSource.EOF
targetrs.AddNew
' For Each Field In rsSource
' targetrs.Fields(Field.Name) = rsSource.Fields(Field.Name)
'
' Next
targetrs!Region = rsSource!REG_NR
targetrs!District = rsSource!DIS_NR
targetrs!EmployeeID = rsSource!TMS_ID
targetrs!EmployeeName = rsSource!EMP_NA
targetrs!Gender = rsSource!EMP_SEX_TYP_CD
targetrs!EEOC = rsSource!EMP_EOC_GRP_TYP_CD
targetrs!Division = rsSource!DIV_NR
targetrs!Center = rsSource!CTR_NR
targetrs!JobTitle = rsSource!JOB_CLS_CD_DSC_TE
targetrs!JobGroupCode = rsSource!JOB_GRP_CD
targetrs!Function = rsSource!Job_Function
targetrs!JobGroup = rsSource!Job_Group
targetrs!MeetingReadinessRating = rsSource!Meeting_Readiness_Rating
targetrs!ManagerReadinessRating = rsSource!Manager_Readiness_Rating
targetrs.Update
rsSource.MoveNext
Loop

rsSource.Close
targetrs.Close


End Sub

我是否错误地指定了记录集?

最佳答案

OpenRecordset 是一个 DAO 方法,返回一个 DAO 记录集。

'Dim targetrs As New ADODB.Recordset
Dim targetrs As DAO.Recordset
Set targetrs = CurrentDb.OpenRecordset("tblEmpData", dbOpenTable)

关于sql - 记录集类型不匹配问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22664618/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com