数据库查询数据丢失
Sub combc()
pdhz = 1
TIM_F2 = Now
If Hour(TIM_F2) = 7 Then
Ado_hzb.RecordSource = "select * from hzc_hz"
Ado_hzb.Refresh
Ado_pdhz.RecordSource = "select jldbh,ghdwbm,shdwbm,wzbm,c_erp01,c_erp02,sum(ljll) as ljhz from hzc_table " & _
" where year(jjrq)='" & Year(Now) & "' and month(jjrq)='" & Month(Now) & _
"' and day(jjrq)='" & Day(Now) & "' and (datepart(hh,jjrq)>=0 and datepart(hh,jjrq)<= 7) group by jldbh,ghdwbm,shdwbm,wzbm,c_erp01,c_erp02"
Ado_pdhz.Refresh
End If
Ado_pdhz.Recordset.MoveFirst
For iii = 0 To Ado_pdhz.Recordset.RecordCount - 1
Ado_hzb.Recordset.AddNew
Ado_hzb.Recordset.Fields("jjrq") = TIM_F2
Ado_hzb.Recordset.Fields("jldbh") = Ado_pdhz.Recordset.Fields("jldbh")
Ado_hzb.Recordset.Fields("ghdwbm") = Ado_pdhz.Recordset.Fields("ghdwbm")
Ado_hzb.Recordset.Fields("shdwbm") = Ado_pdhz.Recordset.Fields("shdwbm")
Ado_hzb.Recordset.Fields("wzbm") = Ado_pdhz.Recordset.Fields("wzbm")
Ado_hzb.Recordset.Fields("c_erp01") = Ado_pdhz.Recordset.Fields("c_erp01")
Ado_hzb.Recordset.Fields("c_erp02") = Ado_pdhz.Recordset.Fields("c_erp02")
Ado_hzb.Recordset.Fields("ljll") = Ado_pdhz.Recordset.Fields("ljhz")
Ado_hzb.Recordset.Fields("c_erp04") = Ado_pdhz.Recordset.Fields("jldbh") & Format(TIM_F2, "yyyymmddhh") & Format(pdhz, "0000")
pdhz = pdhz + 1
Ado_hzb.Recordset.UpdateBatch adAffectCurrent
Ado_pdhz.Recordset.MoveNext
Next iii
qqq:
End Sub
Ado_pdhz.Recordset.Fields("ljhz")的数据和那个sql语句查出来的数据不一样,总是丢数,是什么原因呢?
[解决办法]
是否数据库数据有变动
[解决办法]
不是一个库