使用记录集更新表

时间:2009-12-09 01:06:51

标签: vb6

嗨我有一个记录集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

1 个答案:

答案 0 :(得分:2)

除非您忘记在示例代码中添加某些内容,否则您在Command对象的块内调用了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

同样在向表中写入数据时,建议使用Connection对象BeginTransCommitTrans函数,以防万一在写入数据时出现问题,最终不会出现数据不一致。