Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Inserting multiple values into a db

Status
Not open for further replies.

Cirrus9

IS-IT--Management
Aug 21, 2001
248
US
Hello, I have a question. I have a form that needs to insert several records. Many of the values repeat but only a couple change.

ex:

dataA | dataB | dataC | dataD1
dataA | dataB | dataC1 | dataD1
dataA | dataB | dataC2 | dataD2
dataA | dataB | dataC3 | dataD2

How do I go about repeating through the form values to insert into a db?

Thanks...


 
Do you have any relevant code that shows what you're attempting to do and then, if necessary, we can help you to tweak/fix it.

------------------------------------------------------------------------------------------------------------------------
"Men occasionally stumble over the truth, but most of them pick themselves up and hurry off as if nothing ever happened."
- Winston Churchill
 
Here is the core of the code I am using.
Thanks for your help. In this instance, the only input that ischanges in each record is "choicex"

<form action="insert.asp" method="post" name="frmAdd" id="frmAdd">

<input name="ProdID" type="text" id="ProdID">
<input name="choice1" type="text" id="choice1">
<input name="choice2" type="text" id="choice2">
<input name="choice3" type="text" id="choice3">
<input name="choice3" type="text" id="choice3">
<input name="choice4" type="text" id="choice4">
<input name="choice5" type="text" id="choice5">

<input name="Description" type="text" id="Description" value="">
<input name="Type" type="hidden" id="0">
<Input name="OptInventory" type="hidden" id="OptInventory">
<input name="DropDown" type="text" id="DropDown">
<input name="FmVal" type="text" id="FmVal">
<Input type="hidden" name="attribute" value="Ship To">

</form>

-----------insert.asp----------------

set Insert = Server.CreateObject("ADODB.Command")
Insert.ActiveConnection = MM_sc1_STRING
Insert.CommandText = "INSERT INTO options (ProdID, Attribute, Choice, FmVal, Description, Type, OptInventory) VALUES ((Prodid, Attribute, Choice, FmVal, Description, Type, OptInventory) "
cInsert.CommandType = 1
cInsert.CommandTimeout = 0
cInsert.Prepared = true
cInsert.Execute()
 
Well, if you know exactly how many choices you will have, you can simply loop through them and execute one at a time (there are other options, this is just the first that popped into my head). Something like this:
Code:
set Insert = Server.CreateObject("ADODB.Command")
Insert.ActiveConnection = MM_sc1_STRING
[COLOR=red]for each i = 0 to x [/color][COLOR=green]'x will be the number of choices you have. [/color]
Insert.CommandText = "INSERT INTO options (ProdID, Attribute, Choice, FmVal, Description, Type, OptInventory)  VALUES ((Prodid, Attribute, Choice[COLOR=red]" & i & "[/color], FmVal, Description, Type, OptInventory) "
cInsert.CommandType = 1
cInsert.CommandTimeout = 0
cInsert.Prepared = true
cInsert.Execute()
[COLOR=red]next[/color]

------------------------------------------------------------------------------------------------------------------------
"Men occasionally stumble over the truth, but most of them pick themselves up and hurry off as if nothing ever happened."
- Winston Churchill
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top