I'm attempting to use a Loop which uses an ICount of 1-9 in order to insert data into a database.
The code is used for a website and when this page is loaded there are already values assigned to intProductIDSelected1, intProductIDSelected2 etc so I am attempting to use ICount to join "intProductIDSelected" & intICount which would loop through the 9 intProductIDSelected statements but with no luck.
Below is the code which is causing the problems.
Dim intICount As Integer Dim strTest As String strTest = "intProductIDSelected" & intICount For intICount = 1 To 9 If intTest <> 0 Then Dim strSQLCommand3 As String strSQLCommand3 = "INSERT INTO OrderLine(OrderID, ProductID)" & "Values (" & intMaxOrderID & ", " & strTest & ");" objOleDbConnection.Open() Dim objOleDbCommand3 As System.Data.OleDb.OleDbCommand objOleDbCommand3 = New System.Data.OleDb.OleDbCommand(strSQLCommand3, objOleDbConnection) objOleDbCommand3.ExecuteNonQuery() objOleDbConnection.Close() End If Next
I have tried it with and without the IF statement so this is not causing issues.
I've also tried using single quotes around strTest in the SQL Command, but this just results in the program attempting to enter "intProductIDSelected" into the database as text.
Converting strTest to an Int causes an error.