EvE
08-18-02, 08:42
| I am trying to update multiple records, but with no success yet. I have 2 columns named rbs and code. And I have an asp-page that generates random login codes. Now if I run this code everything works fine. But if I add records after running the code I would like to give them the same logincode if the rbs value is the same or generate new logincodes if the rbs is new. Here is my code. <!--#include file="Adovbs.inc" --> <HTML><BODY><TABLE> <% Randomize() set conn = Server.CreateObject("ADODB.Connection") conn.Open "DRIVER={Microsoft Access Driver (*.mdb)};DBQ="&Server.MapPath("../db/codes3.mdb") set rs = Server.CreateObject("ADODB.Recordset") set rs2 = Server.CreateObject("ADODB.Recordset") rs.open "makecode ORDER BY rbs",conn, adOpenForwardOnly,adLockPessimistic,adCmdTable rbs = "" code = "" while not rs.EOF if rs("rbs") <> rbs then do code = "" for i = 1 to 8 getal = Int(Rnd()*102) if getal>75 then getal=getal+21 elseif getal>49 then getal=getal+47 elseif getal>39 then getal=getal+8 elseif getal>29 then getal=getal+18 elseif getal>19 then getal=getal+28 elseif getal>9 then getal=getal+38 else getal=getal+48 end if code = code & chr(getal) next rs2.open "SELECT rbs FROM makecode WHERE rbs<>'"&rs("rbs")&"' AND code='"&code&"'",conn if rs2.eof then ok=true else ok=false response.write("<TR><TD>CODE EXISTS</TD><TD>REMAKING CODE</TD></TR>") end if rs2.close loop until ok end if rbs = rs("rbs") rs("code") = code response.write("<TR><TD>"&rbs&"</TD><TD>"&code&"</TD></TR>") rs.update rs.movenext wend rs.close set rs=Nothing set rs2=Nothing %> </TABLE</BODY></HTML> |