抱歉的语言,我正在维护一个遗留系统,这是所有的ASP经典。
我有一个html页面,其中包含通过ASP从我的SQL Server生成的内容
<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>现在,我的桌子上方有一个按钮
<button type="submit" value="Submit" class="btn btn-primary mb-2" name="B1">Confirm</button>当我的终端用户单击submit时,我希望所有的值都更新到我的SQL服务器中,现在由于这是在一个for循环中,我不确定Update查询会去哪里。到目前为止,我有这个
<%
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循环中单击submit时,我得到了用逗号分隔的ID号,所以我知道它正在更新,但我真的不确定我做错了什么。
任何帮助都将不胜感激。
如果需要进一步的信息,请让我知道。
预期的输出是在网站上显示一些文章代码代码,并从用户那里获得响应,然后将该输出写入到我的SQL dB,其中文章=文章和ID = ID。
生成内容的主查询(这与我的示例数据不匹配,但我会在查询本身出错的情况下发布)
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)发布于 2019-04-24 21:57:03
希望我能正确理解您,您的数据库中已经有id、quant和文章,并且希望更新与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和文章?一个ID可以有多篇文章吗?反之亦然?
https://stackoverflow.com/questions/55831029
复制相似问题