我不确定为什么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 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