Wrox Programmer Forums

Need to download code?

View our list of code downloads.

| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old April 10th, 2004, 03:54 PM
Authorized User
 
Join Date: Mar 2004
Location: , , .
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
Default case statement troubles!!

Hi,

im new to asp, just trying to learn as i go-i have run into a little trouble with a select case statement. Basically the code takes the users session id which corresponds to his id in the members table then uses this info to get the username. then the code gets all the vegetables which that user has in the veg_root table. Basically i want to go through each veg and work out if its a root,brassica or other type of veg through a select statement, however nothing is output. It does output the veg name if comment out all the case statements etc- heres the code, can anyone help?!!

Dim strUsername, strSQL, strLogUser,strVeg,objRS,varRotation,VarVeg

strSQL = "SELECT username FROM members WHERE id= " & Cint(session("userid"))&";"
              set objRS=objConn.execute(strSQL)
              strUsername=lcase(objRS.Fields("username"))
              objRS.close

strSQL="SELECT*FROM veg_root WHERE username='" & strUsername & "';"

objRS.Open strSQL, objConn, adOpenStatic, adLockReadOnly, adCmdText objRS.MoveFirst


for i=1 to objRS.recordcount

Select Case objRS.Fields("veg_name")
        Case "Artichokes","Beetroot","Carrots","Parsnips","Pota to"
  Response.Write "*"
  Response.Write objRS.Fields("veg_name")
  Response.Write " "
  Response.Write "-crop rotation group: Root"
  Response.Write "<br>"
Case "Brocolli","BrusselSprouts","Cabbage","Cauliflower ","Kale","Swede"
    Response.Write "*"
    Response.Write objRS.Fields("veg_name")
    Response.Write " "
    Response.Write "-crop rotation group: Brassica"
    Response.Write "<br>"
Case "BroadBeans","Celery","Leek","Onions","Peas","Spin ich","Sweetcorn","Tomotoes"
    Response.Write "*"
    Response.Write objRS.Fields("veg_name")
    Response.Write " "
    Response.Write "-crop rotation group: Other"
    Response.Write "<br>"
end select

objRS.MoveNext
next
objRS.close
set objRS = Nothing

Reply With Quote
  #2 (permalink)  
Old April 10th, 2004, 05:57 PM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

I did a little refactoring of your code to simplify things a bit. Perhaps these changes will fix the problem. One thing to do when you have to test strings is to force it to a case so you won't have to worry about the case of the source data.

Dim strUsername, strSQL, strLogUser,strVeg,objRS,varRotation,VarVeg
Dim sRotationGroup

strSQL="SELECT veg_name FROM veg_root vr JOIN members m ON vr.username=m.username WHERE m.id=" & Cint(session("userid")) & ";"

objRS.Open strSQL, objConn, adOpenStatic, adLockReadOnly, adCmdText
If Not (objRS.BOF And objRS.EOF) Then
    While Not objRS.EOF
        Select Case LCase(objRS.Fields("veg_name"))
            Case "artichokes","beetroot","carrots","parsnips","pota to"
                sRotationGroup = "Root"
            Case "brocolli","brusselsprouts","cabbage","cauliflower ","kale","swede"
                    sRotationGroup = "Brassica"
            Case "broadbeans","celery","leek","onions","peas","spin ich","sweetcorn","tomotoes"
                sRotationGroup = "Other"
        End Select
        Response.Write "*"
        Response.Write objRS.Fields("veg_name")
        Response.Write " "
        Response.Write "-crop rotation group: "
        Response.Write sRotationGroup
        Response.Write "<br>"
        objRS.MoveNext
    End While
    objRS.close
End If
Set objRS = Nothing

Peter
-------------------------
Work smarter, not harder
Reply With Quote
  #3 (permalink)  
Old April 10th, 2004, 07:32 PM
Authorized User
 
Join Date: Mar 2004
Location: , , .
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for the reply, i will tryout your suggestions

Cheers

Ronny

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Case statement cole SQL Language 3 May 8th, 2005 03:02 PM
case statement Hudson40 Access VBA 1 February 11th, 2005 11:31 AM
Using A CASE Statement fastcorvette Access 5 December 24th, 2003 01:39 PM
HELP - IF ELSE & CASE statement savoym SQL Language 3 September 12th, 2003 06:35 AM
case statement jakeone Beginning PHP 10 August 19th, 2003 03:03 PM



All times are GMT -4. The time now is 04:56 AM.


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