468,510 Members | 1,733 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,510 developers. It's quick & easy.

Multi Inset to a Database

How can I Multi Inset to a Database? I have been working on but cant seem to get it right. I have a form with unique field names. I am having an issue where I can insert multi records but its inserting blank info too.


-- Form
Expand|Select|Wrap|Line Numbers
  1. <form name="inbound_form" action="Save.asp" method="post">
  2.  
  3. <table width="1226">
  4. <tr>
  5.   <td width="302" class="theader">Provider</td>
  6.   <td width="302" class="theader">Number Type</td>
  7.   <td width="302" class="theader">Network Carrier</td>
  8.   <td width="302" class="theader">Number Function</td>
  9. </tr>
  10. <tr>
  11.   <td><input name="NumberProvider1" type="text" class="textfield" id="NumberProvider" value="" /></td>
  12.   <td><input name="NumberType1" type="text" class="textfield" id="NumberType1" value="" maxlength="" /></td>
  13.   <td><input name="NetworkCarrier1" type="text" class="textfield" id="NetworkCarrier1" value="" /></td>
  14.   <td><input name="NumberFunction1" type="text" class="textfield" id="NumberFunction1" value="" /></td>
  15.   </tr>
  16. <tr>
  17.   <td><input name="NumberProvider2" type="text" class="textfield" id="NumberProvider2" value="" /></td>
  18.   <td><input name="NumberType2" type="text" class="textfield" id="NumberType2" value="" maxlength="" /></td>
  19.   <td><input name="NetworkCarrier2" type="text" class="textfield" id="NetworkCarrier2" value="" /></td>
  20.   <td><input name="NumberFunction2" type="text" class="textfield" id="NumberFunction2" value="" /></td>
  21.   </tr>
  22. <tr>
  23.   <td><input name="NumberProvider3" type="text" class="textfield" id="NumberProvider3" value="" /></td>
  24.   <td><input name="NumberType3" type="text" class="textfield" id="NumberType3" value="" maxlength="" /></td>
  25.   <td><input name="NetworkCarrier3" type="text" class="textfield" id="NetworkCarrier3" value="" /></td>
  26.   <td><input name="NumberFunction3" type="text" class="textfield" id="NumberFunction3" value="" /></td>
  27.   </tr>
  28. <tr>
  29.   <td><input name="NumberProvider4" type="text" class="textfield" id="NumberProvider4" value="" /></td>
  30.   <td><input name="NumberType4" type="text" class="textfield" id="NumberType4" value="" maxlength="" /></td>
  31.   <td><input name="NetworkCarrier4" type="text" class="textfield" id="NetworkCarrier4" value="" /></td>
  32.   <td><input name="NumberFunction4" type="text" class="textfield" id="NumberFunction4" value="" /></td>
  33.   </tr>
  34. <td><input type="submit" name="hidden" id="Save" value="Save &amp; Close" /></td>
  35.   </tr>
  36. </table>
  37. </form>

-- Code
Expand|Select|Wrap|Line Numbers
  1. <%    
  2.     'Dealcare the variables 
  3.             'Dim Conn4, Rs4, NumberProvider, NumberType, NextworkCarrier, NumberStatus, NumberFunction
  4.  
  5.             ' Open objects 
  6.             Set Conn4 = Server.CreateObject("ADODB.Connection")
  7.             Conn4.Open  "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("db.mdb")
  8.  
  9.             'For row = 1 Request.Form("NumberProvider").count
  10.             For row = 1 To 16
  11.             NumberProvider = Left(Request.Form("NumberProvider" & row), 14)
  12.             If IsNull(NumberProvider) OR IsEmpty(NumberProvider) Then Exit For
  13.             NumberProvider = Left(Request.Form("NumberProvider" & Row),14)  
  14.             NumberType = Left(Request.Form("NumberType" & Row),10)  
  15.             NetworkCarrier = Left(Request.Form("NetworkCarrier"& Row),15)  
  16.             NumberStatus = Left(Request.Form("NumberStatus"& Row),12)  
  17.             NumberFunction =  Left(Request.Form("NumberFunction"& Row),14)  
  18.  
  19.             FootPrint_AddedDate = Now
  20.  
  21.             ' Check that field values that are null 
  22.              Response.Write "<br/>"
  23.             Response.Write (NumberProvider)
  24.             Response.Write "<br/>"
  25.             Response.Write (NumberType)
  26.             Response.Write "<br/>"
  27.             Response.Write (NetworkCarrier)
  28.             Response.Write "<br/>"
  29.             Response.Write (NumberStatus)
  30.             'Response.Write "<br/>"
  31.             Response.Write (NumberFunction)
  32.             Response.Write "<br/>"
  33.  
  34.  
  35.             sql4 = "INSERT INTO InventoryStockInbound (NumberProvider, NumberType, NetworkCarrier, NumberStatus, NumberFunction, FootPrint_AddedDate, ShowStock)" _
  36.                     &"VALUES ('"&NumberProvider&"','"&NumberType&"','"&NetworkCarrier&"','"&NumberStatus&"','"&NumberFunction&"','"&FootPrint_AddedDate&"', True)"     
  37.             'SQl4 Debug
  38.             'Response.Write(sql4)
  39.  
  40.             Conn4.Execute sql4
  41.             'End If
  42.             Next
  43.             Conn4 = Close
  44. %>
Aug 7 '12 #1
1 1288
Rabbit
12,513 Expert Mod 8TB
Please use code tags when posting code.

You're only running one INSERT statement so it's only going to insert one row. If you want to insert multiple rows, you'll need to run it multiple times.
Aug 7 '12 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

reply views Thread by Mystic | last post: by
1 post views Thread by socasteel21 via AccessMonster.com | last post: by
7 posts views Thread by =?Utf-8?B?Um9nZWxpbw==?= | last post: by
reply views Thread by slider | last post: by
reply views Thread by NPC403 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.