将两个迭代值添加到更新查询asp-classic中

问题描述 投票:0回答:1

我确定我的错误很简单

我在单个列上有一个来自sqlDB的二维数组

myList = rs.GetRows()

我有html页面,根据我的数组长度输入。 :

<input type="number" name="actual"> 

现在,我要做的是构建一个唯一的SQL更新查询,其中实际列与unique_id列匹配

假设我的列表中只有两个变量。

for each x in my list
 response.write(x)
1,
2

并且只有两个输入,因为输入是由唯一ID生成的

for inputs in response.form("actual")
 response.write(inputs)
55,
66

现在,我想结合这些来构建我的更新查询。

我尝试编写一个double for循环,但这会为输入的每个实例生成一个ID,因此创建4个变量而不是2个

 Unique ID, Input
    1 : 55
    1 : 66
    2 : 55
    2 : 66

我想要的是什么

1 : 55
2 : 66

有人能帮忙吗?我已经在这几个小时了。我不是编码人员,也不是技术背景,而且我在遗留系统和流程中处于领先地位。

我确定字典是可行的,所以我可以生成一对一的关系,但我不知道如何将我的输入转换为列表然后将它们传递到一个字典。

html代码生成我的表:

  <div class="container">
              <table id="table" class="table">
                <thead class="thead-dark">
                  <tr>
                  <th scope="col" data-field="article">Unique ID</th>
                  <th scope="col" data-field="item">Item Name</th>
                  <th scope="col" data-field="quant">Quantity</th>
                  <th scope="col" data-field="act">Actual</th>
              </tr>
              </tr>
            </thead>
            </div>

           <%
           While not grs.eof
          %>
            <tr>
                <th><%=grs.fields("UniqueID")%></th>
                <th><%=grs.fields("itemName")%></th>
                <th><%=grs.fields("quant")%></th>
                <input type="number" class="form-control" id="actual" placeholder="<%=grs.fields("actual")%>" name="Actual">

            <%

            grs.movenext
            Wend
SQL update query goes here %>
vbscript asp-classic
1个回答
1
投票

好的,这里的小事:

你的id对于每一行都不一样,所以像id=actual_<%=grs.fields("UniqueID")%>这样做

你可以试试这个:

<input type="number" class="form-control" id="actual_<%=grs.fields("UniqueID")%>" placeholder="<%=grs.fields("actual")%>" name="actual_<%=grs.fields("UniqueID")%>">

然后在你的循环中:

for each inputs in request.form
   if left(inputs, 7) = "actual_" then
      myId = mid(inputs, 8)
      myValue = request.form("actual_" & myId)

      <your sql statement here>
   end if
next

(您必须添加一些内容来检查您正在检查的输入的名称是否至少有7个字符,否则您将收到错误)

© www.soinside.com 2019 - 2024. All rights reserved.