473,405 Members | 2,300 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Evaluate a recordset value


Hi,

I am new to ASP, HTML and iis.

I have my asp code working so that I can retrieve my desired record
from the database. I can place the data on the screen in table form.
All works fine.

I wish to evaluate one field in the record and depending on the value
in that field I wish to change the colour of the line in the table. As
in a status check.

My DB field is NCHAR.

I need to be able to do something like this....

IF rs.statusoferror = "Closed" THEN
response.write "it works"
END IF

I cannot find a way to return true for - rs.statusoferror = "Closed"
It is like the datatype is not compatible with my variable. If I
write rs.statusoferror to the screen it comes up with - Closed , but I
cannot evaluate with the same text.

I tried CAST, unsuccessfully. Am I barking up the wrong tree?

Cheers for any help.

Dave

Oct 23 '06 #1
11 2702
Dave,

I have resolved a very similar problem by using the following technique:

Firstly define a variable and set this equal to a valid HTML colour based on
the result of your database field value ie:

Dim MyColour

If rs.Fields(“NCHAR”).value = “Closed” Then
MyColour = “FFFFFF” ‘This is white in HTML
Else
MyColour = ‘some other valid HTML colour
End If

Then in the body of your HTML where you define the table add this:

…..bgcolor = <% response.write(MyColour) %……………

A more up to date approach would be to call a different style from your CSS
but still using the same technique.

This is my first posting having started to learn ASP about a year ago, so I
hope it helps you!

Cheers,
Pete
"altreed" wrote:
>
Hi,

I am new to ASP, HTML and iis.

I have my asp code working so that I can retrieve my desired record
from the database. I can place the data on the screen in table form.
All works fine.

I wish to evaluate one field in the record and depending on the value
in that field I wish to change the colour of the line in the table. As
in a status check.

My DB field is NCHAR.

I need to be able to do something like this....

IF rs.statusoferror = "Closed" THEN
response.write "it works"
END IF

I cannot find a way to return true for - rs.statusoferror = "Closed"
It is like the datatype is not compatible with my variable. If I
write rs.statusoferror to the screen it comes up with - Closed , but I
cannot evaluate with the same text.

I tried CAST, unsuccessfully. Am I barking up the wrong tree?

Cheers for any help.

Dave

Oct 23 '06 #2
"altreed" <ca*************@hotmail.comwrote in message
news:11**********************@i42g2000cwa.googlegr oups.com...
IF rs.statusoferror = "Closed" THEN
response.write "it works"
END IF
Is "rs" a recordset and "statusoferror" a field?

If so then try

IF rs("statusoferror") = "Closed" THEN
>If I
write rs.statusoferror to the screen it comes up with - Closed ,
Have you tried

response.write "[" & rs("statusoferror") & "]"

just to check for any invisible characters?

You could also try

response.write vartype(rs("statusoferror"))

--
roger
Oct 23 '06 #3
"altreed" <ca*************@hotmail.comwrote in message
news:11**********************@i42g2000cwa.googlegr oups.com...
>
Hi,

I am new to ASP, HTML and iis.

I have my asp code working so that I can retrieve my desired record
from the database. I can place the data on the screen in table form.
All works fine.

I wish to evaluate one field in the record and depending on the value
in that field I wish to change the colour of the line in the table. As
in a status check.

My DB field is NCHAR.

I need to be able to do something like this....

IF rs.statusoferror = "Closed" THEN
response.write "it works"
END IF

I cannot find a way to return true for - rs.statusoferror = "Closed"
It is like the datatype is not compatible with my variable. If I
write rs.statusoferror to the screen it comes up with - Closed , but I
cannot evaluate with the same text.
The syntax you are using (with the dot operator) treats statusoferror as if
it is a method or property of the recordset object, which it is not. It's a
field name.

If rs("statusoferror") = "Closed" Then
response.write "it works"
End If

Your code should have thrown an error. Do you have On Error Resume Next
further up the page? If so, remove it. It hides error messages that are
helpful in debugging. And what code did you use to successfully get
"Closed" to appear on the page with response.write?

--
Mike Brind
Oct 23 '06 #4

Cheers Guys,

I am amazed how quick the help has come in :D

I was not quoting my code, that is at work and I am off for a couple of
days, so I was mainly just showing my approach rather than code.

Thanks for your guidance, I will have a tinker with your suggestions
and post back my results.

Thanks
Dave

Oct 23 '06 #5

Hi,

Right, I tried the .value method, I received ordinal errors!

Here is the actual ASP

<%
Dim rs, SQL, var, state, variable
state = "Closed"
'Capture the query string from the URL request line
var = Request.querystring("inx")
'create new recordset
Set rs = Server.CreateObject("ADODB.Recordset")

'Define the SQL query criteron
SQL = "SELECT * FROM tblErrorReport WHERE inx = " & var & ""

'Open the recordset with the SQL query
rs.Open SQL, adoCon

'If the data is not in the current table, check the archive table
If rs.EOF then
'close old recordset
rs.Close
'Clear the recordset
Set rs = Nothing
'create new recordset
Set rs = Server.CreateObject("ADODB.Recordset")
'define new SQL query critereon
SQL = "SELECT * FROM tblErrorArchive WHERE inx = " & var & ""
'Open the new recordset with the SQL query
rs.Open SQL, adoCon
end if

' Display record data
Response.Write("{" & rs("stageoferror") & "}")
if rs("stageoferror") = "Closed " then
Response.Write("Arrr")
end if

Response.Write("<table border=" & 1 &">")
Response.Write("<tr>")
Response.Write("<td>Job ID</td>")
Response.Write ("<td>" & var & "</td>")
Response.Write("</tr><tr>")
Response.Write("<td>Date reported</td>")
Response.Write("<td>" & rs("errordate") & "</td>")
Response.Write("</tr><tr>")
Response.Write("<td>Incident reporter</td>")
Response.Write("<td>" & rs("username") & "</td>")
Response.Write("</tr><tr>")
Response.Write("<td>Item requiring attention</td>")
Response.Write("<td>" & rs("computername") & "</td>")
Response.Write("</tr><tr>")
Response.Write("<td>Item located</td>")
Response.Write("<td>" & rs("room") & "</td>")
Response.Write("</tr><tr>")
Response.Write("<td>Stage of response</td>")
Response.Write("<td>" & rs("stageoferror") & "</td>")
Response.Write("</tr><tr>")
Response.Write("</tr><tr>")
Response.Write("<td>Issue reported</td>")
Response.Write("<td>" & rs("error") & "</td>")
Response.Write("</tr><tr>")
Response.Write("<td>Technician assigned</td>")
Response.Write("<td>" & rs("assignedtechnician") & "</td>")
Response.Write("</tr><tr>")
Response.Write("<td>Notes on the issue</td>")
Response.Write("<td>" & rs("notes") & "</td>")
Response.Write("</tr><tr>")
Response.Write("</table>")

'Close and clear recordset
rs.Close
Set rs = Nothing
%>

Here is what is posted (as near as I can replicate the table)

{Closed }
Job ID 999
Date reported 12/01/2006
Incident reporter LONGLANDH
Item requiring attention all those with covers upside down
Item located 014
Stage of response Closed

Issue reported several machines not working in 014, they have the
covers upside down so you can identify them. thanks
Technician assigned FREEMANTLEJ
Notes on the issue Sorted

The ASP code works fine, except for the if/then. I am sure there are
many ways to achieve my table, but the bit that is bothering me is
being able to evaluate the field variable and process according to the
value it holds.

I am not bothered about the table or colour aspect at this time, I need
to be able to evaluate the variable before I am bothered about the
colour of the table row.

Any Help would be appreciated

Thanks
Dave

Oct 24 '06 #6
altreed wrote:
Hi,

Right, I tried the .value method, I received ordinal errors!

Here is the actual ASP

<%
Dim rs, SQL, var, state, variable
state = "Closed"
'Capture the query string from the URL request line
var = Request.querystring("inx")
'create new recordset
Set rs = Server.CreateObject("ADODB.Recordset")

'Define the SQL query criteron
SQL = "SELECT * FROM tblErrorReport WHERE inx = " & var & ""
Don't use selstar: http://www.aspfaq.com/show.asp?id=2096

Help us (and yourself) by stripping your code down to the minimum required
to reproduce your problem.
Start by creating a test page and changing the sql statement to:

SQL = "SELECT stageoferror FROM tblErrorReport WHERE inx = " & var & ""

Then open the recordset and loop through the recordset:

do until rs.eof
response.write rs("stageoferror") & "<BR>"
loop

If this gives you the expected results, then add in the if...then logic,
remembering to use an else clause at this stage of debugging:

do until rs.eof
response.write rs("stageoferror") & "<BR>"
if rs("stageoferror") = "Closed " then
Response.Write("Arrr")
else
Response.Write("stageoferror does not equal Closed")
end if
Response.Write "<BR><BR>"
loop
--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"
Oct 24 '06 #7
"Bob Barrows [MVP]" <re******@NOyahoo.SPAMcomwrote in message
news:eM**************@TK2MSFTNGP04.phx.gbl...
altreed wrote:
>Hi,

Right, I tried the .value method, I received ordinal errors!

Here is the actual ASP

<%
Dim rs, SQL, var, state, variable
state = "Closed"
'Capture the query string from the URL request line
var = Request.querystring("inx")
'create new recordset
Set rs = Server.CreateObject("ADODB.Recordset")

'Define the SQL query criteron
SQL = "SELECT * FROM tblErrorReport WHERE inx = " & var & ""

Don't use selstar: http://www.aspfaq.com/show.asp?id=2096

Help us (and yourself) by stripping your code down to the minimum required
to reproduce your problem.
Start by creating a test page and changing the sql statement to:

SQL = "SELECT stageoferror FROM tblErrorReport WHERE inx = " & var & ""

Then open the recordset and loop through the recordset:

do until rs.eof
response.write rs("stageoferror") & "<BR>"
loop

If this gives you the expected results, then add in the if...then logic,
remembering to use an else clause at this stage of debugging:

do until rs.eof
response.write rs("stageoferror") & "<BR>"
if rs("stageoferror") = "Closed " then
Response.Write("Arrr")
else
Response.Write("stageoferror does not equal Closed")
end if
Response.Write "<BR><BR>"
loop
Adding to what Bob said, you might also want to try Trim(rs("stageoferror"))
to get rid of any whitespace that may have crept in.

"Closed" is not the same as "Closed "

--
Mike Brind
Oct 24 '06 #8


"altreed" wrote:
>
Hi,

Right, I tried the .value method, I received ordinal errors!

Here is the actual ASP

<%
Dim rs, SQL, var, state, variable
state = "Closed"
'Capture the query string from the URL request line
var = Request.querystring("inx")
'create new recordset
Set rs = Server.CreateObject("ADODB.Recordset")

'Define the SQL query criteron
SQL = "SELECT * FROM tblErrorReport WHERE inx = " & var & ""

'Open the recordset with the SQL query
rs.Open SQL, adoCon

'If the data is not in the current table, check the archive table
If rs.EOF then
'close old recordset
rs.Close
'Clear the recordset
Set rs = Nothing
'create new recordset
Set rs = Server.CreateObject("ADODB.Recordset")
'define new SQL query critereon
SQL = "SELECT * FROM tblErrorArchive WHERE inx = " & var & ""
'Open the new recordset with the SQL query
rs.Open SQL, adoCon
end if

' Display record data
Response.Write("{" & rs("stageoferror") & "}")
if rs("stageoferror") = "Closed " then
Response.Write("Arrr")
end if

Response.Write("<table border=" & 1 &">")
Response.Write("<tr>")
Response.Write("<td>Job ID</td>")
Response.Write ("<td>" & var & "</td>")
Response.Write("</tr><tr>")
Response.Write("<td>Date reported</td>")
Response.Write("<td>" & rs("errordate") & "</td>")
Response.Write("</tr><tr>")
Response.Write("<td>Incident reporter</td>")
Response.Write("<td>" & rs("username") & "</td>")
Response.Write("</tr><tr>")
Response.Write("<td>Item requiring attention</td>")
Response.Write("<td>" & rs("computername") & "</td>")
Response.Write("</tr><tr>")
Response.Write("<td>Item located</td>")
Response.Write("<td>" & rs("room") & "</td>")
Response.Write("</tr><tr>")
Response.Write("<td>Stage of response</td>")
Response.Write("<td>" & rs("stageoferror") & "</td>")
Response.Write("</tr><tr>")
Response.Write("</tr><tr>")
Response.Write("<td>Issue reported</td>")
Response.Write("<td>" & rs("error") & "</td>")
Response.Write("</tr><tr>")
Response.Write("<td>Technician assigned</td>")
Response.Write("<td>" & rs("assignedtechnician") & "</td>")
Response.Write("</tr><tr>")
Response.Write("<td>Notes on the issue</td>")
Response.Write("<td>" & rs("notes") & "</td>")
Response.Write("</tr><tr>")
Response.Write("</table>")

'Close and clear recordset
rs.Close
Set rs = Nothing
%>

Here is what is posted (as near as I can replicate the table)

{Closed }
Job ID 999
Date reported 12/01/2006
Incident reporter LONGLANDH
Item requiring attention all those with covers upside down
Item located 014
Stage of response Closed

Issue reported several machines not working in 014, they have the
covers upside down so you can identify them. thanks
Technician assigned FREEMANTLEJ
Notes on the issue Sorted

The ASP code works fine, except for the if/then. I am sure there are
many ways to achieve my table, but the bit that is bothering me is
being able to evaluate the field variable and process according to the
value it holds.

I am not bothered about the table or colour aspect at this time, I need
to be able to evaluate the variable before I am bothered about the
colour of the table row.

Any Help would be appreciated

Thanks
Dave

Dave,

Sorry I did not really understand your question in my first reply.

From what I can see where you have this line:

Response.Write("{" & rs("stageoferror") & "}")

the recordset is closed, and it therefore can't work.

Hope this helps.
Pete
Oct 24 '06 #9
Thanks for your help, I am a noob so please excuse me.

I tried your suggestion with the trim method, I used this code....

Response.Write("{" & Trim(rs("stageoferror")) & "}")
if rs("stageoferror") = "Closed" then
Response.Write("it works")
else
Response.Write("stageoferror does not equal
Closed")
end if

I got this response... Spot the difference....!

{Closed}stageoferror does not equal Closed

No errors, no resume on error....I am flummoxed.

Cheers
Dave

Bob Barrows [MVP] wrote:
altreed wrote:
Hi,

Right, I tried the .value method, I received ordinal errors!

Here is the actual ASP

<%
Dim rs, SQL, var, state, variable
state = "Closed"
'Capture the query string from the URL request line
var = Request.querystring("inx")
'create new recordset
Set rs = Server.CreateObject("ADODB.Recordset")

'Define the SQL query criteron
SQL = "SELECT * FROM tblErrorReport WHERE inx = " & var & ""

Don't use selstar: http://www.aspfaq.com/show.asp?id=2096

Help us (and yourself) by stripping your code down to the minimum required
to reproduce your problem.
Start by creating a test page and changing the sql statement to:

SQL = "SELECT stageoferror FROM tblErrorReport WHERE inx = " & var & ""

Then open the recordset and loop through the recordset:

do until rs.eof
response.write rs("stageoferror") & "<BR>"
loop

If this gives you the expected results, then add in the if...then logic,
remembering to use an else clause at this stage of debugging:

do until rs.eof
response.write rs("stageoferror") & "<BR>"
if rs("stageoferror") = "Closed " then
Response.Write("Arrr")
else
Response.Write("stageoferror does not equal Closed")
end if
Response.Write "<BR><BR>"
loop
--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"
Oct 24 '06 #10
altreed wrote:
Thanks for your help, I am a noob so please excuse me.

I tried your suggestion with the trim method, I used this code....

Response.Write("{" & Trim(rs("stageoferror")) & "}")
if rs("stageoferror") = "Closed" then
How about

if trim(rs("stageoferror"))="Closed" then
--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.
Oct 24 '06 #11
Thanks Bob,

I am indeed a silly winkle. Your astute observation has solved my
quandry.

I am now free to continue with my little application

Great support.

Thanks again
Dave

Bob Barrows [MVP] wrote:
altreed wrote:
Thanks for your help, I am a noob so please excuse me.

I tried your suggestion with the trim method, I used this code....

Response.Write("{" & Trim(rs("stageoferror")) & "}")
if rs("stageoferror") = "Closed" then

How about

******* if trim(rs("stageoferror"))="Closed" then *******
--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.
Oct 24 '06 #12

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Son KwonNam | last post by:
In XSLT, is this possible to get value from xml using XPath which is in XSLT variable? I mean XPath strings can be dynamic while XSL Transforming. If possible, How?? Because I'm not a...
6
by: HKM | last post by:
Hello, I have a query engine that builds the SQL Query to obtain the recordSet. Following is an Exmaple Query that my QueryBuilder outputted SELECT * FROM BookInfo WHERE BookName LIKE...
1
by: Ray Holtz | last post by:
I have a database in Access 2003 (Access2000 file format). There are two tables that are being used: Employees and Items. It is linked by the Employee field so that one employee can have many...
0
by: sienayr | last post by:
Greetings, I have searched hi and lo through the groups and haven't found my problem specifically. I have listed below what I have tried based on what I have found in the groups. Please let me...
2
by: Bjrn Langhof | last post by:
Hello. I want to evaluate a XPath-Expression only on a subtree of the whole xml-document. 1. I select a node of the XML-document 2. Then a want to select specific nodes below the node chosen...
6
by: Oko | last post by:
I'm currently developing an MS Access Data Project (.adp) in MS Access 2002. One of the reports within the DB uses data that is Dynamic and cannot be stored on the SQL Server. To resolve this, I...
6
by: Vince | last post by:
Hello all, I am using Visual Basic to open a saved query and then save information in the query to an array for later use. The problem is that the same query shows different results when opened...
2
by: wallconor | last post by:
Hi, I am having a problem using Dreamweaver CS3 standard recordset paging behavior. It doesnt seem to work when I pass parameter values from a FORM on my search page, to the recordset on my...
4
by: =?Utf-8?B?R1ROMTcwNzc3?= | last post by:
Hi Guys, thanks for your help yesterday, I've got one more question, then I think I'm done for now,... Is it possible to insert recordset data in a javascript, for instance I have a javascript...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development projectplanning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.