I accomplished this in SQL using this code (with sqlParameters):
Dim Command As New SqlCommand(_
"insert into hilmarc_cem_items " & _
"(CEMID, " & _
"ItemCode, " & _
"UnitPrice, " & _
"Quantity, " & _
"UOM) "
Dim ItemCodes() As String = Request.Form.GetValues("ItemCode")
Dim UnitPrices() As String = Request.Form.GetValues("UnitPrice")
Dim Quantities() As String = Request.Form.GetValues("Quantity")
Dim UOMs() As String = Request.Form.GetValues("UOM")
For Counter = 0 To ItemCodes.Length - 1
Command.CommandText &= "select @CEMID, @ItemCode" & Counter & ", @UnitPrice" & Counter & ", @Quantity" & Counter & ", @UOM" & Counter & " "
Command.Parameters.Add("@ItemCode" & Counter, Data.SqlDbType.NVarChar).Value = ItemCodes(Counter)
Command.Parameters.Add("@Quantity" & Counter, Data.SqlDbType.Decimal).Value = Quantities(Counter)
Command.Parameters.Add("@UOM" & Counter, Data.SqlDbType.NVarChar).Value = UOMs(Counter)
Command.Parameters.Add("@UnitPrice" & Counter, Data.SqlDbType.Decimal).Value = UnitPrices(Counter)
If Not Counter = ItemCodes.Length - 1 Then
Command.CommandText &= "union all "
Else
Command.CommandText &= ";"
End If
Next
The idea is to have a single query, get all data from array and add them in sqlCommand as parameters. The query would be like this:
insert into myTable
(CEMID,
ItemCode,
UnitPrice,
Quantity,
UOM)
select @CEMID, @ItemCode0, @UnitPrice0, @Quantity0, @UOM0
union all
select @CEMID, @ItemCode1, @UnitPrice1, @Quantity1, @UOM1
union all
select @CEMID, @ItemCode1, @UnitPrice1, @Quantity1, @UOM1
union all
I'm not sure if this is valid in MySQL, just convert to code to MySQL.