且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

更新SQL Server:在While循环中使用html输入-ASP Classic

更新时间:2022-06-06 22:42:19

希望我能正确理解您的信息,您已经在数据库中找到了id,quant和文章,并希望更新与该ID相关的quant.在这种情况下:

With hopes that I understand you correctly, you have id, quant, and article already in database and want to update the quant related to the ID. In that case:

在创建表单的循环中,为每个数字输入一个名称,名称中带有ID(或者,如果您只有一个字段,则以ID作为名称).就您而言:

In the loop that creates the form give each number input a name with the ID in the name (or if you just have one field just have the ID as the name). In your case:

<input type="number" name="qty<%=rs("ID")%>">

然后在操作页面上循环浏览所有字段并进行相应的更新,或者对名称进行替换以获取ID,或者如果仅使用ID作为字段名,则无需替换即可使用

On the action page you then loop through all the fields and update accordingly, either you do a replace on the name to get the ID, or if you only use the ID as fieldname it works without replace:

For Each Item In Request.Form
            fieldName = Item 'This is the ID (with above field name: qtyID where ID is the ID from the DB.
            fieldValue = Request.Form(Item) 'This is the Quantity of that Article ID
            articleid=replace(fieldName,"qty","")

            sql="update table set qty=" + fieldValue + " where id=" + articleid
Next

这样,您将遍历表格中的所有字段.我也不确定在where子句中是否需要ID和Article?一个ID可以有很多Articles,反之亦然吗?

That way you will go through all the fields in the form. I am also unsure if you need both ID and Article in where clause? Can one ID have many Articles or vice versa?