?
Solved

Query a Recordset

Posted on 2011-09-21
6
Medium Priority
?
274 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 15

Accepted Solution

by:
Eyal earned 1200 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

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

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

I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:   The Exchange of informatio…
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/…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

752 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