0

我需要开具发票的表格,

请帮助我了解如何将所有数据一次插入发票表中。

我正在使用文本框来获取项目的所有详细信息。

这是从表中获取项目详细信息的代码。

enter code here<% While ((Repeat1__numRows <> 0) AND (NOT Recordset1.EOF))%>
          <tr>
            <td><input name="dipatchid" type="text" id="dipatchid" value="<%=(Recordset1.Fields.Item("dispatchid").Value)%>" size="5" /></td>
            <td><input name="dispatchdate" type="text" id="dispatchdate" value="<%=(Recordset1.Fields.Item("dis_date").Value)%>" /></td>
            <td><input type="hidden" name="custid_" id="custid_" />
              <input name="From_" type="text" id="From_" value="<%=(Recordset1.Fields.Item("from_").Value)%>" /></td>
            <td><input name="to_" type="text" id="to_" value="<%=(Recordset1.Fields.Item("To_").Value)%>" /></td>
            <td><input name="hrs" type="text" id="hrs" value="<%=(Recordset1.Fields.Item("total_hrs").Value)%>" size="5" /></td>
            <td><input name="rate_" type="text" id="rate_" size="8" /></td>
            <td><input name="totalamt" type="text" id="totalamt" size="10" /></td>
            <td><img src="imgs/error_icon.png" width="16" height="16" alt="Remove" /></td>              </tr>
          <% Repeat1__index=Repeat1__index+1  Repeat1__numRows=Repeat1__numRows-1  Recordset1.MoveNext() Wend %>

在此处输入图像描述

4

1 回答 1

1

为此,您需要跟踪两件事:

  • 将要插入的行数
  • 每行的数据

做到这一点的技巧,很简单。当你显示你的数据时,你用循环数增加一个变量。

<%
iNumberOfRecords = 0
Do Until Recordset1.EOF
  %>
  <tr>
    <td>
      <input name="dipatchid" type="text" id="..." value="<%=Recordset1("dispatchid")%>" />
    </td>
    ...
  </tr>
  <%
  iNumberOfRecords = iNumberOfRecords + 1
Recordset1.MoveNext
loop
Recordset1.Close
%>

在你关闭你的<form>标签之前,你把它放在一个隐藏的字段中。

<input type="hidden" name="iNumberOfRecords" value="<%=iNumberOfRecords%>" />

接下来,在您提交到的页面上,循环iNumberOfRecords时间以插入所有行。

<%
for i = 1 to CInt(Request.Form("iNumberOfRecords"))
  idOfRecord = GetFormValue("dipatchid", i)
  otherField = GetFormValue("otherField", i)

  SQL = "INSERT INTO tblInvoices(dispatchid, otherfield) VALUES ( " & idOfRecord & ", " & otherfield & " )"
  Connectionobject.Execute(SQL)
next

Function GetFormValue(sFormname, iIndex)
  If Request.Form(sFormname).Count >= iIndex And iIndex > 0 Then
    GetFormValue = Request.Form(sFormname)(iIndex)
  Else
    GetFormValue = ""
  End If
End Function
%>

(i)为您获取正确的项目Request.Form("...")

于 2011-03-15T08:38:03.753 回答