Solved

How to do a dynamic loop in a sql insert statement using ASP classic?

Posted on 2009-05-03
9
375 Views
Last Modified: 2012-05-06
Hi,

I'm trying to do a dynamic loop to insert some data in the DB, but I'm getting no success. The code follows below, and the error message I get is something like:

error 800a000d
Type incompatible: 'SS_Busca_Usuario_Default_'

I think is not being attributed any value to the (x) variable inside the looping, and I don't know what's wrong, any ideas?

Thanks



Dim x
x=1
for x = 1 to 5
 
SS_Busca_Usuario_Default_(x) = "Select ud_nome from users_default WHERE ud_nome = '"& ud_login_(x) &"'"
Set RS_Busca_Usuario_Default_(x) = conn.execute(SS_Busca_Usuario_Default_(x))
 
next

Open in new window

0
Comment
Question by:marcoloppo
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 2
9 Comments
 
LVL 51

Expert Comment

by:Ryan Chong
ID: 24292928
try:

Dim x(5)
x=1
for x = 1 to 5
 
SS_Busca_Usuario_Default_(x) = "Select ud_nome from users_default WHERE ud_nome = '"& ud_login_(x) &"'"
Set RS_Busca_Usuario_Default_(x) = conn.execute(SS_Busca_Usuario_Default_(x))
 
next
0
 
LVL 51

Accepted Solution

by:
Ryan Chong earned 300 total points
ID: 24292954
sorry, should be:

Dim SS_Busca_Usuario_Default_(5)
x=1
for x = 1 to 5
 
SS_Busca_Usuario_Default_(x) = "Select ud_nome from users_default WHERE ud_nome = '"& ud_login_(x) &"'"
Set RS_Busca_Usuario_Default_(x) = conn.execute(SS_Busca_Usuario_Default_(x))
 
next
0
 
LVL 51

Assisted Solution

by:Ryan Chong
Ryan Chong earned 300 total points
ID: 24292956
You may added this as well:

Dim RS_Busca_Usuario_Default_(5)
0
Guide to Performance: Optimization & Monitoring

Nowadays, monitoring is a mixture of tools, systems, and codes—making it a very complex process. And with this complexity, comes variables for failure. Get DZone’s new Guide to Performance to learn how to proactively find these variables and solve them before a disruption occurs.

 
LVL 51

Expert Comment

by:Ryan Chong
ID: 24293471
by the way, "Select ud_nome from users_default WHERE ud_nome = '"& ud_login_(x) &"'" is not an insert SQL statement..
0
 
LVL 6

Expert Comment

by:JoachimMartinsen
ID: 24293589
What is ud_login_(x)? What type is it, and when and where does it get set?
<%
set RS = server.createobject("adodb.recordset")
for x = 1 to 5
	RS.open "Select ud_nome from users_default WHERE ud_nome = '"& ud_login_(x) &"'"
	if not RS.eof then
		' User is found
	end if
	RS.close
next
set RS = nothing
%>

Open in new window

0
 

Author Comment

by:marcoloppo
ID: 24296336
Hi,

Thank you for the answers, I made what was suggested and it worked partly, in other words I got no error message anymore, but the variables:

ud_login_(x)
ud_email_(x)
ud_senha_(x)

Are blank, with no value. I receive via POST the values of these variables, that come from a form, and I got them like below:

ud_login_1 = request("ud_login_1")
ud_email_1 = request("ud_email_1")
ud_senha_1 = request("ud_senha_1")
ud_login_2 = request("ud_login_2")
ud_email_2 = request("ud_email_2")
ud_senha_2 = request("ud_senha_2")
ud_login_3 = request("ud_login_3")
ud_email_3 = request("ud_email_3")
ud_senha_3 = request("ud_senha_3")
ud_login_4 = request("ud_login_4")
ud_email_4 = request("ud_email_4")
ud_senha_4 = request("ud_senha_4")
ud_login_5 = request("ud_login_5")
ud_email_5 = request("ud_email_5")
ud_senha_5 = request("ud_senha_5")

So any of this variables above should be recorded in the SQL statement below, when the loop is running, what might be the problem?

Once thank you.






Dim SS_Busca_Usuario_Default_(5)
Dim ud_login_(5)
Dim RS_Busca_Usuario_Default_(5)
Dim SS_Inclui_User_Master_(5)
Dim ud_email_(5)
Dim ud_senha_(5)
 
x=1
for x = 1 to 5
 
SS_Busca_Usuario_Default_(x) = "Select ud_nome from users_default WHERE ud_nome = '"& ud_login_(x) &"'"
Set RS_Busca_Usuario_Default_(x) = conn.execute(SS_Busca_Usuario_Default_(x))
 
If RS_Busca_Usuario_Default_(x).eof = true then
response.write ud_login_(x)
'SS_Inclui_User_Master_(x) = "Insert into users_default (cod_empresa, ud_nome, ud_email, ud_pass_1, ud_pass_2, ativo, data) VALUES ("& RS_inclui_empresa("IdentityInsert") &", '"& ud_login_(x) &"', '"& ud_email_(x) &"', '"& ud_senha_(x) &"',  '"& md5(ud_senha_(x)) &"',  NULL, getdate())"
'conn.execute(SS_Inclui_User_Master_(x))
end if
 
next

Open in new window

0
 

Author Comment

by:marcoloppo
ID: 24296356
Sorry, below folows the correct script
Dim SS_Busca_Usuario_Default_(5)
Dim ud_login_(5)
Dim RS_Busca_Usuario_Default_(5)
Dim SS_Inclui_User_Master_(5)
Dim ud_email_(5)
Dim ud_senha_(5)
 
x=1
for x = 1 to 5
 
SS_Busca_Usuario_Default_(x) = "Select ud_nome from users_default WHERE ud_nome = '"& ud_login_(x) &"'"
Set RS_Busca_Usuario_Default_(x) = conn.execute(SS_Busca_Usuario_Default_(x))
 
If RS_Busca_Usuario_Default_(x).eof = true then
SS_Inclui_User_Master_(x) = "Insert into users_default (cod_empresa, ud_nome, ud_email, ud_pass_1, ud_pass_2, ativo, data) VALUES ("& RS_inclui_empresa("IdentityInsert") &", '"& ud_login_(x) &"', '"& ud_email_(x) &"', '"& ud_senha_(x) &"',  '"& md5(ud_senha_(x)) &"',  NULL, getdate())"
conn.execute(SS_Inclui_User_Master_(x))
end if
 
next

Open in new window

0
 
LVL 6

Assisted Solution

by:JoachimMartinsen
JoachimMartinsen earned 200 total points
ID: 24297484
Try this:
request("ud_login_"&x)

Open in new window

0
 

Author Closing Comment

by:marcoloppo
ID: 31577448
Great Solution!
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Writing lines of code from a form output in script within a results page 2 37
Date on a table 16 35
ASP AND XML 3 30
SQL to JSON 14 39
If I have to fix slow responding website my first thoughts are server side optimizations: the database may not be optimized or caching is not enabled, or things like that. We often overlook another major part of our web application: the client. We o…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
This video teaches users how to migrate an existing Wordpress website to a new domain.
Learn how to set-up custom confirmation messages to users who complete your Wufoo form. Include inputs from fields in your form, webpage redirects, and more with Wufoo’s confirmation options.

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question