Array of values from Form

Results 1 to 2 of 2

Thread: Array of values from Form

  1. #1
    Join Date
    Dec 1969

    Default Array of values from Form

    My code is below(below everything). I want to take the values from a form and add them to a table by using a loop and avoiding repitious code such as this:<BR>strText1=Request.form("scanned1")<BR>strT ext2=Request.form("scanned2")<BR>ConnRS.AddNew<BR> ConnRS("UPC")=strText1<BR>ConnRS.Update<BR>ConnRS. AddNew<BR>ConnRS("UPC")=strText2<BR>ConnRS.Update< BR><BR><BR>Dim ConnRS<BR>Dim strSQL<BR>Dim conn<BR>Dim strText1,strText2<BR>strText1=Request.form("scanne d1")<BR>strText2=Request.form("scanned2")<BR><BR>s et conn=Server.CreateObject("ADODB.Connection")<BR>co nn.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("scannedinventory.mdb")<BR><BR><BR> Set ConnRS = Server.CreateObject("ADODB.Recordset")<BR><BR>strS QL = "SELECT tbl_ScannedProducts.UPC FROM tbl_ScannedProducts"<BR><BR><BR>ConnRS.Open strSQL, conn, AdOpenDynamic, AdLockOptimistic<BR>ConnRS.AddNew<BR>ConnRS("UPC") =strText1<BR>ConnRS.Update<BR>ConnRS.AddNew<BR>Con nRS("UPC")=strText2<BR>ConnRS.Update

  2. #2
    Join Date
    Dec 1969

    Default If you named that nicely...

    ...then it&#039;s easy:<BR><BR>&#060;%<BR>...<BR>ConnRS.Open strSQL, conn, AdOpenDynamic, AdLockOptimistic<BR><BR>For pnum = 1 To MAXPNUM<BR> upc = Request("scanned" & pnum).Value<BR> If Trim(upc) &#060;&#062; "" Then<BR> ConnRS.AddNew<BR> ConnRS("UPC") = <BR> ConnRS.Update<BR> End If<BR>Next<BR>%&#062;<BR><BR>I think you&#039;d be better off using SQL than using AddNew, but that&#039;s a different issue.<BR><BR>How do you know what the value of MAXPNUM is/should be? But storing *IT* in a hidden field on the &#060;FORM&#062;:<BR> &#060;INPUT Type="Hidden" Name="scanned_count" Value="7"&#062;<BR>and then doing<BR>&#060;%<BR>MAXPNUM = Request("scanned_count")<BR>%&#062;<BR>on the ASP page.<BR><BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts