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 April 10th, 2004, 03:54 PM
Authorized User
 
Join Date: Mar 2004
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

 
Old April 10th, 2004, 05:57 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
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
 
Old April 10th, 2004, 07:32 PM
Authorized User
 
Join Date: Mar 2004
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for the reply, i will tryout your suggestions

Cheers

Ronny






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





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