WillShakespeare
MIS
Hia ll,
I have the following code. I am trying to select a RecordSet from a table based on a Client ID. Then, based on my looping, delete only those records that have the same ID as in the array. The idea is I have a number of funds attached to a client in the table Investments. And someone needs to update this table to reflect a customers need to be withdrawn from an (or many) investment fund.
The following code, if you select, say four funds for deletion, deletes the first in that list, but then an exception is raised on the inner If clause (arrFundsOff(i) = objRS("FundID")), seemingly after one deletion has taken place.
Now, if I remove the delete and instead build a table dynamically of the values to be deleted, the resulting table (commented out in my code) does reflect exactly, the funds that should be deleted,a nd the code runs fine. It is only when I add the Delete statement (and I have tried using Update at various places too), that an exception occurs.
Can anyone help? I have poured over the MSDN site on ADO, and been careful to select the appropriate Cursor and locktype, etc. I have noted talk of UpdateBatch (or BatchUpdate), but I am not sure if this is relevant. It "seems" what I am trying to do should work, and is within the ability of ADO, but my code just won't work!!!
Please help if you can!
strSQL = "Select * FROM Investments WHERE ClientID = " & intUserID
Set objRS = Server.CreateObject("ADODB.Recordset")
objRS.Open strSQL, objConn, 2, 3
'strTableTest = "<table><tr><td><b>i</b></td><td width=""50""></td><td><b>Fund ID</b></td><td width=""50""></td><td><b>arrFundsOff(i) ID</b></td><td width=""50""></td></tr><tr><td colspan = ""6""><hr></td></tr>"
Do While objRS.EOF <> True
For i = 0 to Ubound(arrFundsOff)
If arrFundsOff(i) <> "xxx" Then
If arrFundsOff(i) = objRS("FundID") Then
'strTableTest = strTableTest & "<tr><td>" & i & "</td><td width=""50""></td><td>" & objRS("FundID") & "</td><td width=""50""></td><td>" & arrFundsOff(i) & "</td><td width=""50""></td></tr>"
objRS.Delete
'objRS.Update
'objRS.Close
'Set objRS = Nothing
End If
End If
Next
'objRS.Update
objRS.MoveNext
'objRS.Update
Loop
objRS.Close
'strTableTest = strTableTest & "</table>"
'Response.Write(strTableTest)
Thanks in adavnce,
Will
I have the following code. I am trying to select a RecordSet from a table based on a Client ID. Then, based on my looping, delete only those records that have the same ID as in the array. The idea is I have a number of funds attached to a client in the table Investments. And someone needs to update this table to reflect a customers need to be withdrawn from an (or many) investment fund.
The following code, if you select, say four funds for deletion, deletes the first in that list, but then an exception is raised on the inner If clause (arrFundsOff(i) = objRS("FundID")), seemingly after one deletion has taken place.
Now, if I remove the delete and instead build a table dynamically of the values to be deleted, the resulting table (commented out in my code) does reflect exactly, the funds that should be deleted,a nd the code runs fine. It is only when I add the Delete statement (and I have tried using Update at various places too), that an exception occurs.
Can anyone help? I have poured over the MSDN site on ADO, and been careful to select the appropriate Cursor and locktype, etc. I have noted talk of UpdateBatch (or BatchUpdate), but I am not sure if this is relevant. It "seems" what I am trying to do should work, and is within the ability of ADO, but my code just won't work!!!
Please help if you can!
strSQL = "Select * FROM Investments WHERE ClientID = " & intUserID
Set objRS = Server.CreateObject("ADODB.Recordset")
objRS.Open strSQL, objConn, 2, 3
'strTableTest = "<table><tr><td><b>i</b></td><td width=""50""></td><td><b>Fund ID</b></td><td width=""50""></td><td><b>arrFundsOff(i) ID</b></td><td width=""50""></td></tr><tr><td colspan = ""6""><hr></td></tr>"
Do While objRS.EOF <> True
For i = 0 to Ubound(arrFundsOff)
If arrFundsOff(i) <> "xxx" Then
If arrFundsOff(i) = objRS("FundID") Then
'strTableTest = strTableTest & "<tr><td>" & i & "</td><td width=""50""></td><td>" & objRS("FundID") & "</td><td width=""50""></td><td>" & arrFundsOff(i) & "</td><td width=""50""></td></tr>"
objRS.Delete
'objRS.Update
'objRS.Close
'Set objRS = Nothing
End If
End If
Next
'objRS.Update
objRS.MoveNext
'objRS.Update
Loop
objRS.Close
'strTableTest = strTableTest & "</table>"
'Response.Write(strTableTest)
Thanks in adavnce,
Will