【发布时间】:2017-08-05 02:48:33
【问题描述】:
我正在尝试将 NUM_ID 更新为 1,其中 NUM_ID 为 4。
我的表格看起来像这个范围 A1:A6
NUM_ID 1 1 4 2 2
Excel 在下面的代码中返回错误“没有为一个或多个必需参数提供值”。
Sub Update()
Dim strNUM_ID As Double
Dim strSQL As String
Dim cnn As ADODB.Connection
strNUM_ID = 1
strSQL = "UPDATE [Sheet1$] " & _
"SET [NUM_ID] = strNUM_ID " & _
"WHERE [NUM_ID] = 4;"
Debug.Print strSQL
Set cnn = New ADODB.Connection
With cnn
.Provider = "Microsoft.ACE.OLEDB.12.0"
.ConnectionString = "Data Source=C:\Temp" & _
"Test.xlsm;" & _
"Extended Properties=Excel 12.0;"
.Open
.Execute strSQL, DbFailOnError
End With
cnn.Close
Set cnn = Nothing
End Sub
使用 Excel 2010
【问题讨论】:
标签: sql excel sql-update vba