Click to See Complete Forum and Search --> : For Each Loop


jacknbey
12-05-2004, 11:21 AM
Hi All,

Need help :)

I have an asp POST FORM with the following multi-value parameters passed to next ASP page.

RecordName = Record1, Record2, Record3
Number = 1, 2, 3
Code = A, B, C
Currency = AUD, USD, EUR
Value = 800, 600, 400


I need to insert new records into SQL database as followed:-

RecordName(nvarchar),Number(nvarchar),Code(nvarchar),Currency(nvarchar),Value(money)

Record1,1,A,AUD,800
Record2,2,B,USD,600
Record3,3,C,EUR,400


How do I use the For Each loop (or in fact anything will do) to parse them into the the above record?


If I use :-

For Each RecordName
For Each Number
For each Code
.
.
.
Next
Next
Next

It seems ridiculously redundant to me.

Can I use:-

For Each RecordName,Number,Code... instead?



Thanks all...

russell
12-05-2004, 01:16 PM
RecordName = Record1, Record2, Record3
Number = 1, 2, 3
Code = A, B, C
Currency = AUD, USD, EUR
Value = 800, 600, 400

arRecordName = split(Request.Form("RecordName"), ",")
arNumber = split(Request.Form("Number"), ",")
arCode = split(Request.Form("Code"), ",")
arCurrency = split(Request.Form("Currency"), ",")
arValue = split(Request.Form("Value"), ",")

For i = 0 to ubound(arRecordName)
sql = "INSERT INTO MyTable (RecordName, Number, Code, Currency, Value) " &_
"VALUES ('" & arRecordName(i) & "', " & arNumber(i) & ", '" & arCode(i) &_
"', '" & arCurrency(i) & "', " & arValue(i) & ")"
...
Next


Of course, you should use stored procedures and the command object if you are using MS SQL Server, for better efficiency and security.

jacknbey
12-05-2004, 08:35 PM
Thanks Rus,

Do you mind if I ask for 2 gmail invites from you?

Regards,
Jack