2009-12-09 81 views
0

嗨我有一個記錄集rcdDNE。我想通過對現有記錄集做一些條件來更新我的回收。但我的表沒有更新。你們能告訴我我在哪裏做錯了嗎?使用記錄集更新表

Dim lngRecCount As Long 

frmDNELoad.lblStatus.Caption = "Updating records in Reclamation Table..." 
frmDNELoad.Refresh 
CqDate = Format(Date, "dd/MM/yyyy") 

Set rcdreclamation = New ADODB.Recordset 
With rcdreclamation 
    .ActiveConnection = objConn 
    .Source = "SELECT * FROM T_DATA_reclamation" 
    .CursorType = adOpenDynamic 
    .CursorLocation = adUseClient 
    .LockType = adLockOptimistic 
    .Open 
End With 

rcdDNE.MoveFirst 

Do Until rcdDNE.EOF 
With cmdDNEFRC 
    .ActiveConnection = objConn 
    .CommandText = "update t_data_reclamation set ClaimStatus = 'C',DateClosed = 'CqDate', Audit_LastUpdated = 'CqDate', Audit_UserAdded = 'SYSTEM' where RTProvided = '" & rcdDNE("AccountNbr") & "'" 
    .CommandType = adCmdText 
End With 

rcdDNE.MoveNext 
Loop 

回答

2

除非它的東西你忘了把你的示例代碼,你缺少的Execute函數的調用內部命令對象與塊。

With cmdDNEFRC 
    .ActiveConnection = objConn 
    .CommandText = "update t_data_reclamation set ClaimStatus = 'C',DateClosed = 'CqDate', Audit_LastUpdated = 'CqDate', Audit_UserAdded = 'SYSTEM' where RTProvided = '" & rcdDNE("AccountNbr") & "'" 
    .CommandType = adCmdText 
    .Execute 'dont forget execution 
End With 

而且寫入數據時表,使用連接對象BeginTrans和建議CommitTrans功能,以防萬一有寫你不與數據不一致,最終數據時出錯。