Vba 更新SQL表不工作
我不知道为什么vba更新sql表的更改不起作用。我在电子表格顶部有一个按钮来更新记录 存储过程正在更新。但当通过excel完成时,它不会接受更新。请查看Vba 更新SQL表不工作,vba,excel,Vba,Excel,我不知道为什么vba更新sql表的更改不起作用。我在电子表格顶部有一个按钮来更新记录 存储过程正在更新。但当通过excel完成时,它不会接受更新。请查看 Sub Employee_Button2_Click() Dim sBackupUpdQry As String Dim sUpdQry As String Dim iRows As Integer Dim qryUpdateArray(4000) As String Dim iCols As Integ
Sub Employee_Button2_Click()
Dim sBackupUpdQry As String
Dim sUpdQry As String
Dim iRows As Integer
Dim qryUpdateArray(4000) As String
Dim iCols As Integer
On Error GoTo ErrHandler
Dim lLastRow As Long
Dim lLastCol As Integer
lLastRow = Cells.Find("*", Range("A3"), xlFormulas, , xlByRows, xlPrevious).Row ' Find the last row with data
lLastCol = Cells.Find("*", Range("A3"), xlFormulas, , xlByColumns, xlPrevious).Column ' Find the last column with data
Dim iRecCount As Integer
With Sheets("Select and Update Employee")
sBackupUpdQry = "EXEC usp_UpdateEmployee_FTE"
iRows = 3
iRecCount = 1
For iRecCount = 1 To lLastRow - 3
iRows = iRows + 1
sUpdQry = ""
sUpdQry = sUpdQry + " , @GroupingParm = '" + CStr(Cells(iRows, 3)) + "'"
sUpdQry = sUpdQry + " , @CCNumParm = '" + CStr(Cells(iRows, 4)) + "'"
sUpdQry = sUpdQry + " , @CCNameParm = '" + CStr(Cells(iRows, 5)) + "'"
sUpdQry = sUpdQry + " , @ResTypeNumParm = '" + CStr(Cells(iRows, 6)) + "'"
sUpdQry = sUpdQry + " , @ResNameParm = '" + CStr(Cells(iRows, 7)) + "'"
sUpdQry = sUpdQry + " , @StatusParm = '" + CStr(Cells(iRows, 8)) + "'"
sUpdQry = sBackupUpdQry + " @EmpIDParm = '" + CStr(Cells(iRows, 1)) + "' " + " , @ENameParm = '" + CStr(Cells(iRows, 2)) + "' " + sUpdQry
qryUpdateArray(iRecCount) = sUpdQry
'oConn.Execute qryUpdateArray(iRecCount)
Next iRecCount
End With
Call DBConnection.OpenDBConnection
Dim rsMY_Resources As ADODB.Recordset
Set rsMY_Resources = New ADODB.Recordset
Dim cntUpd As Integer
cntUpd = 0
For iRecCount = 1 To lLastRow - 3
If qryUpdateArray(iRecCount) > "" Then
oConn.Execute qryUpdateArray(iRecCount)
cntUpd = cntUpd + 1
End If
Next iRecCount
Call DBConnection.CloseDBConnection
MsgBox ("Employee_FTE has been updated")
Exit Sub
ErrHandler:
MsgBox (Error)
End Sub
将
中的
更改为
,如果qryUpdateArray(iAccount)>“,则。在此行之后,插入debug.print qryUpdateArray(iAccount)
。使用输出更新您的问题(其中的一些)。同时在oConn之前添加一些Debug.Print qryUpdateArray(ireAccount)
。如果qryUpdateArray(ireAccount)在即时窗口中有效,则执行qryUpdateArray(ireAccount)
ans ee。如果您有疑问,请将第一个贴在这里。猜猜看。。将值从excel传输到SP参数时,会使该值略有不同,并且不再与要更新的记录匹配。我建议您首先将错误转到时的全部删除。如果你有问题,这有时会隐藏一些东西。当它工作时,你可以把它放回去。无论如何,您基本上需要逐步检查代码并密切注意参数值(是否有多余的空格、逗号或不必要的引号?)。在中将
更改为
,如果qryUpdateArray(iAccount)>”,则。在此行之后,插入debug.print qryUpdateArray(iAccount)
。使用输出更新您的问题(其中的一些)。同时在oConn之前添加一些Debug.Print qryUpdateArray(ireAccount)
。如果qryUpdateArray(ireAccount)在即时窗口中有效,则执行qryUpdateArray(ireAccount)
ans ee。如果您有疑问,请将第一个贴在这里。猜猜看。。将值从excel传输到SP参数时,会使该值略有不同,并且不再与要更新的记录匹配。我建议您首先将错误转到时的全部删除。如果你有问题,这有时会隐藏一些东西。当它工作时,你可以把它放回去。无论如何,您基本上需要逐步完成代码并密切关注参数值(是否有额外的空格、逗号或不需要的引号?)。