How to assign value into recordset?
Hi all,
i want to assign the value to the specify recordset
below is my coding:
Code:
For i = 0 To Rs.RecordCount - 1
If DateAdd("s", Rs("Frequency"), Rs("Lastreaddate")) > Now Then
tmpOPCItem(i).Read OPCDataSource.OPCDevice, myValue(i), myQuality(i), myTimeStamp(i)
'strAddress() = Split(tmpOPCItem(i).ItemID, ":")
tmpValue = myValue(i)
'strSQL = "Select Address,LineId,LifterId,ComponentId,TriggerValue,ResetValue, " _
& "ActionId,ActionPara1,OPCServer,RealTimeData,timeCounter " _
& "from DELL_OPC_ADDRESS where processing <> 1 " _
& "and Active=1 and OPCServer=" & txtOPC.Text & " " _
& "and Address='" & strAddress(1) & "'"
'RsOPC.Open strSQL, Conn, adOpenStatic, adLockBatchOptimistic
strTrigger = Rs("TriggerValue")
If tmpValue <> "" Then
NeedTrigger = False
Select Case strTrigger
Case "EMPTY"
If CStr(tmpValue) = "" Then NeedTrigger = True
Case "NONEMPTY"
If CStr(tmpValue) <> "" Then NeedTrigger = True
Case "TRUE", "FALSE"
If CBool(tmpValue) = CBool(strTrigger) Then
NeedTrigger = True
End If
Case "NONZERO"
If IsNumeric(tmpValue) Then
If CDbl(tmpValue) <> 0 Then NeedTrigger = True
End If
Case "0", "1", "2"
If tmpValue = strTrigger Then NeedTrigger = True
End Select
'Check if the TriggerValue stays there forever (due to ResetValue='NO ACTION').
'If yes, then make sure TriggerValue <> RealTimeData
If NeedTrigger And Rs.Fields("ResetValue") = "NO ACTION" Then
If tmpValue = Rs.Fields("RealTimeData") Then NeedTrigger = False
End If
End If
If NeedTrigger Then 'If tmpValue.ToUpper = CType(DR("triggerValue"), String).ToUpper Then
' theValue = tmpValue
Set NewItem = lstviewEvent.ListItems.Add(, , Rs.Fields("LifterId"))
NewItem.ListSubItems.Add , , Rs.Fields("Address")
NewItem.ListSubItems.Add , , myValue(i)
NewItem.ListSubItems.Add , , Time
End If
Rs("LastReadDate") = Now
End If
'Conn.Close
Rs.MoveNext
Next
'Loop
mytime = (GetTickCount() - mytime)
MsgBox "TimeStamp: " & mytime & vbNewLine & "RecordCount: " & Rs.RecordCount
'Timer1.Enabled = True
I want to update the recordset ( Rs("LastReadDate") ) become the time now. But failed to do so.
Can someone have a clear guide to me?
thanks.
Re: How to assign value into recordset?
Welcome to VBForums :wave:
After setting the field value(s), you need to specify that you want to write those values to the database, which you do with: rs.Update
(or cancel the changes with: rs.CancelUpdate)
Re: How to assign value into recordset?
Quote:
Originally Posted by si_the_geek
Welcome to VBForums :wave:
After setting the field value(s), you need to specify that you want to write those values to the database, which you do with: rs.Update
(or cancel the changes with: rs.CancelUpdate)
hi, thanks your reply.
after the code Rs("LastReadDate") = Now, it jump to the excepetion error.
Multiple-step OLE DB operation generated errors. Check each OLE DB status value, if available. No work was done
Re: How to assign value into recordset?
See this for an explanation of how to find what the actual error(s) were.