2011-03-15 119 views
0

我需要一張發票表格,經典Asp + Ajax進銷存

請幫我解釋一下如何將所有的數據一次性插入發票表。

我正在使用文本框來獲取項目的所有詳細信息。

這裏是從表中獲取項目的細節的代碼。

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 %> 

enter image description here

+0

是否要將* Form *數據插入數據庫表中?完全不清楚你想要做什麼。 – 2011-03-15 08:46:04

+0

是的,我想要將表單數據插入到db表中,但問題是首先我要從一個表中讀取數據以進行審計...然後將其發佈到其他表中。數據沒有修復。行的,其變化 – Dev 2011-03-15 12:55:14

回答

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("...")項目適合你。

+0

HI, 感謝答覆,我得到這個錯誤 「請求對象錯誤ASP 0105:80004005' 索引超出範圍 /united/insertinvoice.asp 18行 數組索引超出範圍 「 代碼是 」<% 對於i = 0至CINT(的Request.Form(「 iNumberOfRecords」)) idOfRecord =的Request.Form( 「dipatchid」)(ⅰ) otherField = Request.Form(「dispatchdate」)(i) custid = Request.Form(「custid」)(i) SQL =「INSERT INTO inv DAT(DISPID,disdate,客戶ID)VALUES( 「&idOfRecord&」, 「&otherfield&」, 「&客戶ID& 」)「 Connectionobject.Execute(SQL) 下 %> 」 – Dev 2011-03-17 04:39:28

+0

對不起,無法正常工作,同錯誤,可能是我們傳遞給數組的值很大,如1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1 ,1,2,2,12,1,2,1,1,1,1,1,2,21,21,21,1,1,1,121,521,1,1,1,1,522,52,5,11 ,1,52 – Dev 2011-03-17 14:46:27

+0

你是什麼意思? – 2011-03-17 14:58:41