|
-
Apr 8th, 2005, 06:19 AM
#1
Thread Starter
Junior Member
sql with loop and var
Hi,
I wish to loop around an array putting the values into a mysql table.
Code:
For y = LBound(arrquery) To UBound(arrquery)
With rdoQry
.SQL = "INSERT INTO `Query` ( `Query_ID` , `Query_text` , `Answered` )VALUES ('', 'arrquery(y)', '0')"
Set .ActiveConnection = cnMySql
.Execute
End With
cnMySql.Close
Next y
arrquery() is my array, but it doesnt like me putting it in the SQL like that, what do i need to put round the arrquery(y) to make sure that it knows thar it is a variable i am posting to it, not a string.
Thanks in advance for any help
-
Apr 8th, 2005, 06:21 AM
#2
Re: sql with loop and var
First - not sure if MySql requires it - but single quotes around the table name is not standard SQL...
Something like:
Code:
For y = LBound(arrquery) To UBound(arrquery)
With rdoQry
.SQL = "INSERT INTO Query ( `Query_ID` , `Query_text` , `Answered` )VALUES ('', '" & arrquery(y) & "', '0')"
Set .ActiveConnection = cnMySql
.Execute
End With
cnMySql.Close
Next y
-
Apr 8th, 2005, 06:27 AM
#3
Thread Starter
Junior Member
Re: sql with loop and var
Thanks, that has half solved my problem.
The loop works once now, however when it loops the 2nd time i get an error:
"Object invalid or not set" on the following line of code:
Code:
.SQL = "INSERT INTO `Query` ( `Query_ID` , `Query_text` , `Answered` )VALUES ('', '" & arrquery(y) & "', '0')"
Do you have any idea why this might be?
-
Apr 8th, 2005, 06:31 AM
#4
Re: sql with loop and var
Sorry about that - didn't notice you were closing the connection in the loop...
Remove that line - actually drop it below the Next statement...
-
Apr 8th, 2005, 06:41 AM
#5
Thread Starter
Junior Member
Re: sql with loop and var
thanks... it works now
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|