更新 SQL 服务器:在 While 循环中使用 html 输入 - asp 经典

Update SQL Server: with html-input within a While Loop - asp classic

对语言表示歉意,我正在维护一个遗留系统,该系统全部在 ASP Classic 中。

我有一个 html 页面,其中包含从我的 SQL 服务器通过 ASP

生成的内容
<form method="POST"> 
<div class="container">
 <table id="table" class="table">
  <thead class="thead-dark">
  <tr>
  <th scope="col" data-field="article">Article</th>
  <th scope="col" data-field="item">QTY/th>

然后我从我的 dB 中用 while 循环生成了内容,它正确显示了内容:

<%
 While not grs.eof
%>
<tr>
<!--SQL query from ASP-classic-->
<th><%=grs.fields("Article")%></th>
<input type="number" class="form-control" id="Quant" placeholder="<%=grs.fields("QTY")%>" name="qty"></th>

<%
 grs.movenext
wend   
%>
</tr>
</table>
</form>

现在,在我的 table 上方有一个按钮

<button type="submit" value="Submit" class="btn btn-primary mb-2" name="B1">Confirm</button>

当我的最终用户点击提交时,我希望所有值都更新到我的 SQL 服务器中,现在因为这是在 for 循环中,我不确定更新查询会去哪里..到目前为止我有这个

<%
If request.form("B1")="Submit" Then
If QTY = "" Then
QTY = 0
Else
QTY = request.form("QTY")
'Update SQL'
gsSQL2 = "UPDATE dB SET quant ='" & QTY & "' WHERE ID = '" & request.querystring("ID") & "' And Article = '" & grs.fields("Article") &"'"
gobjConn.Execute(gsSQL2)

(请注意我的代码在 IDE 中正确缩进)

现在,当我在 While 循环中单击提交时,我得到了用逗号分隔的 ID 号,所以我知道它正在更新,但我真的不确定我做错了什么..?

如有任何帮助,我们将不胜感激。

如果需要任何进一步的信息,请告诉我。

预期输出是在网站上显示一些 Article Codes 代码并获取用户的响应,然后将该输出写入我的 SQL dB,其中 Article = Article 和 ID = ID。

生成内容的主要查询(这与我的示例数据不匹配,但我会 post 以防错误出在查询本身)

gsSQL = "SELECT ID, Article, [Item Name] as name, [Stock Quantity] as qty, Built, Boxed, Actual from dB where Store ='" & request.querystring("store") & "' order by [Category], name "
Set grs = gobjConn.Execute(gsSQL)

希望我没理解错,您的数据库中已经有 id、quant 和 article,想更新与 ID 相关的 quant。在那种情况下:

在创建表单的循环中,为每个数字输入一个名称,名称中包含 ID(或者如果您只有一个字段,则只需将 ID 作为名称)。你的情况:

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

然后在操作页面上遍历所有字段并进行相应更新,或者对名称进行替换以获取 ID,或者如果仅将 ID 用作字段名,则无需替换即可工作:

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 可以有多篇文章,反之亦然?