|
楼主 |
发表于 2023-7-6 17:44
|
显示全部楼层
问题自行解决(但并不是我一开始的设想,Sql = "update lc1 set lc1.量能=arrt(4, i1) where lc1.ID”,希望得到老师帮助!),代码如下:
Sub 同时更新数据()
Dim CNN As New ADODB.Connection
Dim Sj As New ADODB.Recordset
Dim i1
myData = ThisWorkbook.Path & "\000004" & ".mdb"
With CNN: .Provider = "microsoft.jet.oledb.4.0"
.Open myData
End With
Sql = "SELECT lc1.ID,lc1.日期, lc1.收盘,lc1.交量,lc1.量能 FROM lc1 ORDER BY lc1.ID asc"
Sj.Open Sql, CNN, adOpenKeyset, adLockOptimistic
arrt = CNN.Execute(Sql).GetRows
'起始行7根据条件不同而随意得到
For i1 = 7 To UBound(Application.Index(arrt, 1, 0)) - 1
'在尾部随意减了10000数据,让arrt数组内存量能有了变化
arrt(4, i1) = (arrt(2, i1) - arrt(2, i1 - 1)) * arrt(3, i1) - 10000
Sj.Fields("量能").Value = arrt(4, i1)
Sj.MoveNext '数据库指针下移一位
Next i1
CNN.Close: Set Sj = Nothing: Set CNN = Nothing
End Sub
|
|