Advertisement

02.10.2008 at 06:58AM PST, ID: 23151333
[x]
Attachment Details

Loop with sql query

Asked by vico1 in Active Server Pages (ASP), SQL Query Syntax

Tags: ASP, VB

I have this update query, it works. However I need to create a loop with it since I have to update 40 rows.
I have tried to do it with a Do Loop, but I don't see how to replace the numbers with the variables.
Take a look below at the query:
Assuming that you have done so, the Numbers that I am talking about are the from the variables: Request("NAMEx") x being the numbers.
The first set of codes are the codes tested without a loop so I know that it works.
The second set of codes is the loop but I believe that it's wrong.
Can somebody please help me with this matter. I am a novice on programming, I do it as a Hobby.
Thanks in advance, Start Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
-----------FIRST SET WORKS
<%
   set objConnection=Server.CreateObject("ADODB.Connection")
   objConnection.ConnectionTimeout = 15
   objConnection.CommandTimeout =  10
   objConnection.Mode = 3 'adModeReadWrite 
      if objConnection.state = 0 then
         objConnection.Open Application("DB_Connection_ConnectionString")
      end if
 
      strSQL1 = "UPDATE SYS_GRID " & _
            "SET G_NAME = '" & Request("GRID1") & "', " & _
            "G_CAT = '" & Request("CATGRID1") & "', " & _
            "G_PCT = '" & Request("PCTGRID1") & "', " & _
            "G_TYPE = " & Request("GRIDTYPE1") & " " & _
            "WHERE (G_NUMBER) = 1 ;"
      objConnection.Execute strSQL1
      
      strSQL2 = "UPDATE SYS_GRID " & _
            "SET G_NAME = '" & Request("GRID2") & "', " & _
            "G_CAT = '" & Request("CATGRID2") & "', " & _
            "G_PCT = '" & Request("PCTGRID2") & "', " & _
            "G_TYPE = " & Request("GRIDTYPE2") & " " & _
            "WHERE (G_NUMBER) = 2 ;"
      objConnection.Execute strSQL2
   objConnection.Close
%>
------------------SECOND SET LOOKS WRONG AND I GET NO ANSWER
 
<%
   Dim Gcount
   Gcount=1
   set objConnection=Server.CreateObject("ADODB.Connection")
   objConnection.ConnectionTimeout = 15
   objConnection.CommandTimeout =  10
   objConnection.Mode = 3 'adModeReadWrite 
   
   DO Until Gcount = 41
      if objConnection.state = 0 then
         objConnection.Open Application("DB_Connection_ConnectionString")
      end if
 
      strSQL = "UPDATE SYS_GRID " & _
            "SET G_NAME = '" & Request("GRID" & Gcount & "") & "', " & _
            "G_CAT = '" & Request("CATGRID" & Gcount & "") & "', " & _
            "G_PCT = '" & Request("PCTGRID" & Gcount & "") & "', " & _
            "G_TYPE = " & Request("GRIDTYPE" & Gcount & "") & " " & _
            "WHERE (G_NUMBER) = " & Gcount & " ;"
      objConnection.Execute strSQL
      Gcount=Gcount+1
   Loop   
   objConnection.Close
%>
[+][-]02.10.2008 at 07:31AM PST, ID: 20861372

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]02.10.2008 at 07:46AM PST, ID: 20861425

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]02.10.2008 at 07:47AM PST, ID: 20861429

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]02.10.2008 at 07:55AM PST, ID: 20861453

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]02.10.2008 at 07:57AM PST, ID: 20861456

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]02.10.2008 at 09:16AM PST, ID: 20861681

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]02.10.2008 at 11:00AM PST, ID: 20862043

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]02.11.2008 at 09:12AM PST, ID: 20868040

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]02.11.2008 at 11:01AM PST, ID: 20869091

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]02.11.2008 at 11:47AM PST, ID: 20869517

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]02.11.2008 at 11:55AM PST, ID: 20869598

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: Active Server Pages (ASP), SQL Query Syntax
Tags: ASP, VB
Sign Up Now!
Solution Provided By: GreenGhost
Participating Experts: 2
Solution Grade: A
 
 
[+][-]02.11.2008 at 01:11PM PST, ID: 20870271

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628