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

Hi all, I am totally puzzled ove

Status
Not open for further replies.

JoJoH

Programmer
Joined
Jan 29, 2003
Messages
356
Location
US
Hi all,

I am totally puzzled over this piece of code:

<%
Dim iCount
iCount = Request.Form(&quot;Count&quot;)

Dim strSize, strImgURL, strSQL


Dim Command1
set Command1 = Server.CreateObject(&quot;ADODB.Connection&quot;)
Command1.ConnectionString = Connection_String
Command1.Open

Dim iLoop
For iLoop = 0 to iCount
strSize = Request(iLoop & &quot;.varSize&quot;)
strImgURL = Request(iLoop & &quot;.ImgURL&quot;)

strSQL = &quot;INSERT INTO Table (ProductID, [Size], ImgURL) VALUES ('&quot;& varProductID &&quot;', '&quot;& strSize &&quot;', '&quot;& strImgURL &&quot;')&quot;

Command1.Execute strSQL
Next
Command1.Close
Set Command1 = Nothing

%>

Basically what this piece of code should do is to retrieve the necessary values and insert it into the database &quot;iCount&quot; number of times.

Now say the iCount variable is 3, then it should insert into the database 3 times, but instead it inserted into the database 6 times(if iCount is 4 then instead of inserting 4 times it inserted 8 times).

I did a Response.Write(&quot;&quot;& iCount &&quot;&quot;) to make sure the iCount variable is correct and yes it indeed is a 3... so the counter variable is correct but it is just not behaving...

But when I inserted the number directly--instead of
For iLoop = 0 to iCount I put
For iLoop = 0 to 3
then everything works fine... Please advice.

Thanks in advance!

JoJoH

 
I think your variable iCount hasn't been read in Number variable type such as integer or double or any others.
it's my suggestion...
Code:
Dim iCount
iCount = Request.Form(&quot;Count&quot;)
iCount = Cint(iCount)

the last syntax maybe helpful.

*JJ* [smile]
 
Thanks JJ for your reply! I've just tried what you said above but it is still returning the same problem...

Please advice.

Thanks in advance

JoJoH

 
Are you positive that the value of icount is what you think it is?

Put a response.write(Request.Form(&quot;Count&quot;)) at the top somewhere to make sure it is only 3 or 4 and not 6 or 8.

Transcend
[gorgeous]
 
Thanks Trancend, Thanks Gary for the replies!

I did a response.write(&quot;&quot;& iCount &&quot;&quot;) and the result is correct. I did a response.write(&quot;&quot;& strSQL &&quot;&quot;) and it showed that it inserted the correct info for 3 times(which is correct) But in the database it showed that it has 6 records(inserted 6 times)...

Please advice.

Thanks in advance

JoJoH

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top