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 Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

inserting records from a for...next statement HELP!!

Status
Not open for further replies.

bikebanditcom

Programmer
Jun 11, 2003
117
US
i have a form that has a dynamic portion, so the form works, the variables are passing as i'm writing them to the screen on the take_returns.asp page. my problem is that i don't know how to write the insert statement for this loop. could anyone help please, i had it written another way, but that way i defined the insert statement at ever for...next and it inserted the records one at a time by themselves instead of one big record. any ideas?

'this block loops thru the part info section and inserts a record for each row
set adminDB = Server.CreateObject("ADODB.Connection")
adminDB.open "admin"

for each partNumber in request.form("partNumber")
partInfo = partInfo & request.form("partNumber")
next
for each qty in request.form("qty")
partInfo = partInfo & request.form("qty")
next
for each dealer in request.form("dealer")
partInfo = partInfo & request.form("dealer")
next
for each mercValue in request.form("mercValue")
partInfo = partInfo & request.form("mercValue")
next
for each reason in request.form("reason")
partInfo = partInfo & request.form("reason")
next
for each shipped in request.form("shipped")
partInfo = partInfo & request.form("shipped")
next
for each UnreturnableToSupp in request.form("UnreturnableToSupp")
partInfo = partInfo & request.form("UnreturnableToSupp")
next
for each CrdtToBeIssd in request.form("CrdtToBeIssd")
partInfo = partInfo & request.form("rdtToBeIssd")
next
for each Rcvd15Day in request.form("Rcvd15Day")
partInfo = partInfo & request.form("Rcvd15Day")
next
for each custRestockingFee in request.form("custRestockingFee")
partInfo = partInfo & request.form("custRestockingFee")
next


adminDB.Execute(partInfoInsert)

adminDB.close

set adminDB = Nothing
%>
 
Think I got this for you in another thread...

The way you're form data and table are mean that you'll need the 2-dimensional array....

dim fieldArr()
redim fieldArr(9,0) 'assuming 10 total fields for each record'

'if you have fields that do not fit the name_## format, you may need to alter this to handle them'

for each item in request.form
underscorePos = inStr(item, "_")
recordNum = mid(request.form(item), underscorePos + 1)
if recordNum > uBound(fieldArr,2) then
redim preserve(fieldArr(9,cInt(recNum)))
end if
select case left(item,underscorePos - 1)
case "partNumber"
arrPos = 0
case "qty"
arrPos = 1
case "dealer"
arrPos = 2
'complete for all items

end select
fieldArr(arrPos, cInt(recNum)) = request.form(item)
next

'now just write you sql for each record'
for x = 1 to uBound(fieldArr,2)
sql = "INSERT myTable VALUES("&_
"'" & fieldArr(0,x) & "'," &_
"'" & fieldArr(1,x) & "'," &_
"'" & fieldArr(2,x) & "'," &_
'continue for all records and add a closing ")"
cn.execute (sql)
next


Programming today is a race between software engineers striving to build better and bigger idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rick Cook
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top