Solved

Query a Recordset

Posted on 2011-09-21
6
235 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Table header not displaying on Firefox and Chrome 7 141
Copy only dates 3 81
Need help editing script 3 67
Change visitor's REMOTE_ADDR to server's REMOTE_ADDR 2 20
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
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/…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

863 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

23 Experts available now in Live!

Get 1:1 Help Now