Wrox Programmer Forums
|
Classic ASP Databases Discuss using ASP 3 to work with data in databases, including ASP Database Setup issues from the old P2P forum on this specific subtopic. See also the book forum Beginning ASP.NET Databases for questions specific to that book. NOT for ASP.NET 1.0, 1.1, or 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Databases section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 23rd, 2005, 03:40 PM
Authorized User
 
Join Date: Jan 2005
Posts: 42
Thanks: 0
Thanked 0 Times in 0 Posts
Default Problem with FOR Statement

In the code below I am trying to use a group of checkboxes to insert information into two different tables. I have two questions here.

1. The first FOR statement works but it inserts the info in the database in one record seperated by a comma such as..

deaID RegionName
________________________________
449 | Houston,Hometown

I need it to put each value in a new record like so..

deaID RegionName
________________________________
449 | Houston
449 | Hometown


2. The second For statement doesn't work at all and I think it is because the information has already been used in the first FOR statement so it "no longer exists"???.

Is this right?....if so how do I fix it?

<%

deaID=request("deaID")


For each chk in request("regionname")
if chk <> "" then
     sql3 = "INSERT into DealerRegions (deaID,RegionName) Values ('"&deaID&"','"&request("regionname")&"')"
    end if
        set addregion = conn.execute(sql3)
NEXT

For each chk in request("regionname")
if chk <> "" then
     sql = "SELECT RegionCodes.zipcode FROM RegionCodes WHERE RegionName='" & request("regionname") & "'" '& "Order by RegionCodes.zipcode"
    end if
'sql = "SELECT RegionCodes.zipcode FROM RegionCodes WHERE RegionName='" & region & "'" & "Order by RegionCodes.zipcode"
        set getregioncodes = conn.execute(sql)

    Do while not getregioncodes.eof
            sql2 = "INSERT INTO NewDealercodes (deaID, dealercode) Values ('"&deaID&"',"&getregioncodes("zipcode")&")"
            response.write "SQL2 is " & sql2 & ""
            set addzipcodes = conn.execute(sql2)
        getregioncodes.MoveNext
    loop
next
%>
 
Old February 23rd, 2005, 04:39 PM
Friend of Wrox
 
Join Date: May 2004
Posts: 642
Thanks: 0
Thanked 43 Times in 42 Posts
Default

Use the following:

if chk <> "" then
       sql = "SELECT RegionCodes.zipcode FROM RegionCodes WHERE RegionName='" & chk & "'" '& "Order by RegionCodes.zipcode"


Om Prakash
 
Old February 23rd, 2005, 11:18 PM
Authorized User
 
Join Date: Jan 2005
Posts: 42
Thanks: 0
Thanked 0 Times in 0 Posts
Default

OK that solved the problem of it not going to the second FOR Statement but...It is still loading the information into the first table seperated by a comma instead of in seperate records...

I illustrated this in my original post...

 
Old February 23rd, 2005, 11:22 PM
Authorized User
 
Join Date: Jan 2005
Posts: 42
Thanks: 0
Thanked 0 Times in 0 Posts
Default

nevermind I use the same solution for both questions...thanks.






Similar Threads
Thread Thread Starter Forum Replies Last Post
If statement problem chris1012 ASP.NET 3.5 Basics 3 September 9th, 2008 05:52 PM
problem with if...or...then statement lightmaker Classic ASP Basics 7 June 9th, 2008 06:49 PM
Where statement problem lryckman Access VBA 4 June 29th, 2007 08:46 AM
problem with delete statement thas123 SQL Server 2000 6 March 23rd, 2006 01:13 PM
Problem with "where = " select statement shirley65 SQL Language 3 October 17th, 2005 04:07 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.