Solved

Query a Recordset

Posted on 2011-09-21
6
220 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
  • 3
  • 2
6 Comments
 
LVL 28

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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
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 28

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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
This video discusses moving either the default database or any database to a new volume.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

759 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

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now