更新SQL Server:在While循环中使用html输入-ASP Classic [英] Update SQL Server: with html-input within a While Loop - asp classic
问题描述
关于语言的道歉,我维护的是遗留系统,所有这些都在ASP Classic中.
Apologies about the language, I'm maintaining a legacy system which is all in ASP Classic.
我有一个html页面,其中包含通过ASP从我的SQL Server生成的内容
I have a html page which has content generated from my SQL Server via 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循环生成了内容,该循环正确显示了内容:
I then generated the content with a while loop from my dB which displays the content correctly :
<%
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>
现在,在我的桌子上方,我有一个按钮
Now, above my table I have a button
<button type="submit" value="Submit" class="btn btn-primary mb-2" name="B1">Confirm</button>
当我的最终用户单击提交"时,我希望将所有值更新到我的SQL Server中,因为这是在for循环中,所以我不确定更新"查询的去向./p>
When my end user clicks submit, I want all the values to be updated into my SQL server, now as this is within a for loop I wasn't sure where the Update query would go.. I have this so far
<%
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中已正确缩进)
(please note my code is indented properly in my IDE)
现在,当我在While循环中单击Submit时,我得到的ID号用逗号分隔,因此我知道它正在更新,但是我真的不确定自己在做什么错..?
Now, when I click submit within the While loop I get the ID number seperated by a comma, so I know it's updating but I'm really unsure as to what I'm doing wrong..?
任何帮助将不胜感激.
如果需要任何其他信息,请告诉我.
if any further information is needed let me know.
预期的输出是在网站上显示一些文章代码"代码并获得用户的响应,然后将该输出写入我的SQL dB,其中文章=文章"和"ID = ID".
Expected output is to display some Article Codes codes on a website and take a response from the user, then write that output to my SQL dB where the Article = Article and ID = ID.
对生成内容的主查询(这与我的示例数据不匹配,但是如果错误是查询本身,我将进行发布)
main query to generated content (this doesn't match my sample data but I'll post incase the mistake is in the query itself)
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和文章,并希望更新与该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?
这篇关于更新SQL Server:在While循环中使用html输入-ASP Classic的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!