Click to See Complete Forum and Search --> : Update not working!


leeny
02-23-2005, 03:50 AM
i need to update the database according to the checkboxes that are checked. my problem now is the form only gets one EMPID instead of several (suppose to be 22 of them). therefore it updates the database to changes the EmpID to the one that is being retrieved. can anyone point out what's wrong?



If Request("Submit")="Submit" then

id=request.form("id")

Dim strSelection,arrSelection

strSelection = request.form("emp")
strSelection = CStr(strSelection)
arrSelection = Split(strSelection, ", ")

For i = 0 to UBOUND(arrSelection)
sql10 = "Update ProjectAllocation Set PID = "&id&", EmpID = " & arrSelection(i) & ""
Set Rs10 = Server.CreateObject("ADODB.RecordSet")
Rs10.open sql10,conn
Next
%>

<%Else%>
<form action="editProj.asp" name="form1" method="post">
<input name="id" type="hidden" value="<%=id%>" size="35">

<table width="57%" border="0" align="center" cellpadding="4" cellspacing="4">
<tr>
<td colspan="2"><div align="center"><font size="4" face="Verdana, Arial, Helvetica, sans-serif"><strong>Edit
Project Details</strong></font></div></td>
</tr>
<tr bgcolor="#0000CC">
<td colspan="2"><div align="left"><strong><font color="#FFFFFF" size="2" face="Verdana, Arial, Helvetica, sans-serif">Edit
</font></strong></div></td>
</tr>
<tr bgcolor="#CCCCCC">
<td colspan="2"><div align="left"><font color="#000000" size="2" face="Arial, Helvetica, sans-serif"><strong>Employees
who are involved:</strong></font></div></td>
</tr>
<tr bgcolor="#CCCCCC">
<td colspan="2">
<table width="550" border="0" cellspacing="1" cellpadding="1">
<tr>
<td>
<table width="538" height="41" border="0" cellpadding="1" cellspacing="1">
<tr>
<%
rwset=1
ct=1
Do while not rs1.eof
%>
<td width="534" height="37"><div align="left">
<input name="emp" type="checkbox" id="emp" value="<%=RS1("EMPID")%>" checked>
<font color="#000000" size="2" face="Arial, Helvetica, sans-serif"><strong><%=RS1("EMPID")%></strong></font></label>
<%
f=rwset mod 5
if(f=0) then
%>
</td>
</tr>
<%
end if
ct=ct+1
rwset=rwset+1


rs1.movenext
loop
%>

</table>&nbsp;
</td>
</tr>
</table>

phpnovice
02-23-2005, 08:18 AM
I have not checked for myself, but the following code presumes the list is delimited by both a command and a space:

strSelection = request.form("emp")
strSelection = CStr(strSelection)
arrSelection = Split(strSelection, ", ")

Have you verified that the list is not delimited by just a comma and NO space? Otherwise, in the following code:

For i = 0 to UBOUND(arrSelection)
sql10 = "Update ProjectAllocation Set PID = "&id&", EmpID = " & arrSelection(i) & ""
Set Rs10 = Server.CreateObject("ADODB.RecordSet")
Rs10.open sql10,conn
Next

doesn't your Update need a Where clause so that it knows what row to update? Also, creating a new recordset for each update is not only a problem (in terms of storage), but is not required. So, perhaps that code should be restructured as follows:

For i = 0 to UBOUND(arrSelection)
sql10 = "Update ProjectAllocation Set PID = "&id&" Where EmpID = " & arrSelection(i) & ";"
conn.Execute sql10
Next

Otherwise, perhaps you need to use Insert, instead?