Solved

Query a Recordset

Posted on 2011-09-21
6
270 Views
Last Modified: 2012-08-13
Hi All,

If I query my SQL Database: "Select ProductCode from ShoppingCart Where SessionID = x" and place the results into a recordset (rs) - everything works fine.

What I want to do is now say:
If Product123 is listed in rs.fields.productcode Response.Write("xxx") ELSE Response.Write("yyy")

Can this be easily achieved?
0
Comment
Question by:powellt77
[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
  • 3
  • 2
6 Comments
 
LVL 29

Expert Comment

by:sammySeltzer
ID: 36577405
Do you mean:

SQL = "Select ProductCode from ShoppingCart Where SessionID = x" 

set rs=conn.execute(SQL)

DO UNTIL RS.EOF
ProdCode = RS("ProductCode")

If ProdCode = 'Product123' Then
   Response.Write "xxx"
Else
  Response.Write "yyy"
End If
RS.MoveNext
Loop

Open in new window

0
 
LVL 15

Expert Comment

by:Eyal
ID: 36578336
I would not loop thru the rs. there is a simpler way.

http://www.w3schools.com/ado/prop_rs_filter.asp
0
 

Author Comment

by:powellt77
ID: 36583182
Thank You both - Eval, the filter option looks like it could work.
I'm trying not to hammer the server, but understand it'll need to do some work.

I'm new to the ADO Filter property - would you be kind enough to show roughly how I'd implement it?
0
Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

 
LVL 15

Accepted Solution

by:
Eyal earned 300 total points
ID: 36594248
something like that

Dim Value
Value = "Product123"

SQL = "Select ProductCode from ShoppingCart Where SessionID = x" 

set rs=conn.execute(SQL)

rs.Filter = "ProductCode = '"&Value &"'" 

if not (rs.EOF or rs.BOF)
 Response.Write "xxx"
Else
  Response.Write "yyy"
End If

Open in new window

0
 
LVL 29

Expert Comment

by:sammySeltzer
ID: 36594289
WOW!
This is simpler and more elegant?
0
 
LVL 15

Expert Comment

by:Eyal
ID: 36594420
powellt77: I didn't mentioned it but if you can query the database again it will be the fastest solution

sammySeltzer:
first your code moves thru out all the records and print for each record the xxx/yyy. I assume this is not what is needed.
second, do you think your code is better from what Microsoft wrote inside the ADO library for the Recordset object?

0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
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/…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

688 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