0

我需要检索产品信息。从数据库中,现在想要编辑一些数据并将其保存回数据库。我创建了编辑表单页面并将值传递给另一个保存页面。我想要的只是保存已编辑的记录,但是当我单击“保存”按钮时,所有记录的数据都通过了。我困惑的是使用相同的传递方法,我只能成功删除特定的记录。

这是我的代码..

<table cellpadding="0" cellspacing="0" border="1" width="100%">
    <tr class="border bluebackend" >
        <td class="center bold" width="30">Size</td>
        <td class="center bold" width="30">Color</td>
        <td class="center bold" width="27%">Est. Qty (dz.)</td>
        <td class="center bold" width="30">&nbsp;</td>
        <td class="center bold" width="30">&nbsp;</td>
    </tr>
<%
dim total_qty_est, total_qty
if rsPdtn_sizeColor.eof then 
response.Write "<tr><td colspan=""3"">file not found</td></tr>"
Else                      
Do while Not rsPdtn_sizeColor.EOF

total_qty_est = rsPdtn_sizeColor.fields.item("pdtn_st_qty_est")
total_qty = total_qty + total_qty_est       

%>                                              
    <tr >
        <td class="center">
            <select name="pdtn_st_size">
                <option selected>-- size -- </option>
                <option value="L" <%=checkSelectedScript(rsPdtn_sizeColor.fields.item("pdtn_st_size"),"L")%>>L</option>
                <option value="XL" <%=checkSelectedScript(rsPdtn_sizeColor.fields.item("pdtn_st_size"),"XL")%>>XL</option>

            </select>                                                                    
        </td>
        <td class="center">
            <select name="pdtn_st_color">
                <option selected>-- color -- </option>
                <option value="Orange" <%=checkSelectedScript(rsPdtn_sizeColor.fields.item("pdtn_st_color"),"Orange")%>>Orange</option>
                <option value="Pink" <%=checkSelectedScript(rsPdtn_sizeColor.fields.item("pdtn_st_color"),"Pink")%>>Pink</option> 
            </select>                                                                         
        </td>
         <td class="center">
            <input type="text" value="<%=PcsToDz(rsPdtn_sizeColor.fields.item("pdtn_st_qty_est"))%>" name="pdtn_st_qty_est" size="3">
            &nbsp;&nbsp;(<%=rsPdtn_sizeColor.fields.item("pdtn_st_qty_est")%>)
         </td>
        <td><input type="button" name="" value="Del" onClick="confirmationDeletePrice('../engine/delPdtn_szCl.asp?pdtn_szcl_id= <%=rsPdtn_sizeColor.fields.item("pdtn_szcl_id")%>&pdtn_st_id=<%=rsPdtn_sizeColor.fields.item("tbl_pdtn_sizecolor.pdtn_st_id")%>')"></td>     
        <td class="center" >
        <input type="button" name="" value="Save" onClick="confirmationSaveProduction_Szcl('production_szcl_edit_action.asp?pdtn_szcl_id= <%=rsPdtn_sizeColor.fields.item("pdtn_szcl_id")%>')">

         <input type="hidden" value="Y" name="edit_pdtn_szcl">
          <input type="hidden" value="<%=rsPdtn_sizeColor.fields.item("pdtn_szcl_id")%>" name="pdtn_szcl_id">                                                                    
        </td>                                                               
    </tr>
<%
rsPdtn_sizeColor.movenext

Loop    
rsPdtn_sizeColor.movefirst
end if
%>       

这是我的保存页面代码...

<%
    pdtn_st_id = Request.form("pdtn_st_id")
    pdtn_st_qty_est_dz = Request.form("pdtn_st_qty_est")

        if pdtn_st_qty_est_dz <> "" then
            pdtn_st_qty_est = DztoPcs(pdtn_st_qty_est_dz)
        end if

    pdtn_st_size =   Request.form("pdtn_st_size")   
    pdtn_st_color =   Request.form("pdtn_st_color") 
    edit_pdtn_szcl =   Request.form("edit_pdtn_szcl")   

    call checkBlank(pdtn_st_qty_est)

    if SomethingError <> "yes" then

        Call DBConnOpen()

            Set Rs = Server.CreateObject("ADODB.Recordset")
            Set Rs.ActiveConnection = Conn

            strSQL = "SELECT * FROM tbl_pdtn_sizecolor"
                pdtn_szcl_id = Request.form("pdtn_szcl_id")
                strSQL = strSQL & " WHERE pdtn_szcl_id =" & pdtn_szcl_id & ""
                Rs.Open strSQL, Conn, 1, 3          

            Rs.Fields("pdtn_st_id") = pdtn_st_id
            Rs.Fields("pdtn_st_qty_est") = pdtn_st_qty_est
            Rs.Fields("pdtn_st_size") = pdtn_st_size    
            Rs.Fields("pdtn_st_color") = pdtn_st_color  

            Rs.Update
            Rs.Close

            response.redirect "production_view.asp?pdtn_st_id=" & pdtn_st_id

        Call DBConnClose()

    else
        call writeInputError
    end if
%>      
4

1 回答 1

1

最简单的解决方案是将现有标签移动到循环中的表格行周围。这样您就可以一次编辑一行,而无需修改您的保存页面代码。

我在下面的代码中添加了表单标签,但您需要使用您已经在使用的 FORM 标签:

<table cellpadding="0" cellspacing="0" border="1" width="100%">
    <tr class="border bluebackend" >
        <td class="center bold" width="30">Size</td>
        <td class="center bold" width="30">Color</td>
        <td class="center bold" width="27%">Est. Qty (dz.)</td>
        <td class="center bold" width="30">&nbsp;</td>
        <td class="center bold" width="30">&nbsp;</td>
    </tr>
<%
dim total_qty_est, total_qty
if rsPdtn_sizeColor.eof then 
response.Write "<tr><td colspan=""3"">file not found</td></tr>"
Else                      
Do while Not rsPdtn_sizeColor.EOF

total_qty_est = rsPdtn_sizeColor.fields.item("pdtn_st_qty_est")
total_qty = total_qty + total_qty_est       

%>
    <form action="" method=""><!--move your form open tag here-->                                       
    <tr >
        <td class="center">
            <select name="pdtn_st_size">
                <option selected>-- size -- </option>
                <option value="L" <%=checkSelectedScript(rsPdtn_sizeColor.fields.item("pdtn_st_size"),"L")%>>L</option>
                <option value="XL" <%=checkSelectedScript(rsPdtn_sizeColor.fields.item("pdtn_st_size"),"XL")%>>XL</option>

            </select>                                                                    
        </td>
        <td class="center">
            <select name="pdtn_st_color">
                <option selected>-- color -- </option>
                <option value="Orange" <%=checkSelectedScript(rsPdtn_sizeColor.fields.item("pdtn_st_color"),"Orange")%>>Orange</option>
                <option value="Pink" <%=checkSelectedScript(rsPdtn_sizeColor.fields.item("pdtn_st_color"),"Pink")%>>Pink</option> 
            </select>                                                                         
        </td>
         <td class="center">
            <input type="text" value="<%=PcsToDz(rsPdtn_sizeColor.fields.item("pdtn_st_qty_est"))%>" name="pdtn_st_qty_est" size="3">
            &nbsp;&nbsp;(<%=rsPdtn_sizeColor.fields.item("pdtn_st_qty_est")%>)
         </td>
        <td><input type="button" name="" value="Del" onClick="confirmationDeletePrice('../engine/delPdtn_szCl.asp?pdtn_szcl_id= <%=rsPdtn_sizeColor.fields.item("pdtn_szcl_id")%>&pdtn_st_id=<%=rsPdtn_sizeColor.fields.item("tbl_pdtn_sizecolor.pdtn_st_id")%>')"></td>     
        <td class="center" >
        <input type="button" name="" value="Save" onClick="confirmationSaveProduction_Szcl('production_szcl_edit_action.asp?pdtn_szcl_id= <%=rsPdtn_sizeColor.fields.item("pdtn_szcl_id")%>')">

         <input type="hidden" value="Y" name="edit_pdtn_szcl">
          <input type="hidden" value="<%=rsPdtn_sizeColor.fields.item("pdtn_szcl_id")%>" name="pdtn_szcl_id">                                                                    
        </td>                                                               
    </tr>
    </form><!--move your form close tag here-->
<%
rsPdtn_sizeColor.movenext

Loop    
rsPdtn_sizeColor.movefirst
end if
%>       
于 2012-09-11T22:35:04.303 回答