Niedawno spotkałem się z instrukcjami aktualizacji vba i używam Recordset.Edit
i Recordset.Update
, aby nie tylko edytować moje istniejące dane, ale również je aktualizować.Zestaw Recordset.Edit lub Update sql vba najszybszym sposobem aktualizacji?
Chcę poznać różnicę między dwoma oświadczeniami: recordset.update
i Update sql Vba
. Myślę, że wszyscy robią to samo, ale nie potrafię określić, który z nich jest skuteczniejszy i dlaczego.
Przykładowy kod poniżej:
'this is with sql update statement
dim someVar as string, anotherVar as String, cn As New ADODB.Connection
someVar = "someVar"
anotherVar = "anotherVar"
sqlS = "Update tableOfRec set columna = " &_
someVar & ", colunmb = " & anotherVar &_
" where columnc = 20";
cn.Execute stSQL
To dla rekordów (aktualizacja i Edit):
dim thisVar as String, someOthVar as String, rs as recordset
thisVar = "thisVar"
someOthVar = "someOtherVar"
set rs = currentDb.openRecordset("select columna, columnb where columnc = 20")
do While not rs.EOF
rs.Edit
rs!columna = thisVar
rs!columnb = someOthvar
rs.update
rs.MoveNext
loop
Ile wierszy jest wybranych przez "WHERE columnc = 20"? Jeden rząd? Milion wierszy? – HansUp
Załóżmy, że 1000 plus –