评估记录集值 [英] Evaluate a recordset value

查看:79
本文介绍了评估记录集值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述






我是ASP,HTML和iis的新手。


我有我的asp代码工作,以便我可以从数据库中检索我想要的记录

。我可以将表格中的数据放在屏幕上。

一切正常。


我希望评估记录中的一个字段并根据值

在该字段中我希望更改表格中行的颜色。在状态检查中为




我的DB字段是NCHAR。


我需要能够做这样的事情....


IF rs.statusoferror =" Closed"然后

response.write它的工作原理

结束如果


我找不到回复真实的方法 - rs .statusoferror =" Closed"

这就像数据类型与我的变量不兼容。如果我

将rs.statusoferror写入屏幕,它会出现 - 已关闭,但是我不能用相同的文字评估



我试过CAST,但未成功。我吵了一棵错误的树吗?


欢呼任何帮助。


Dave

解决方案

戴夫,


我通过使用以下技术解决了一个非常类似的问题:


首先定义一个变量并将其设置为基于

的有效HTML颜色数据库字段值的结果即:


Dim MyColour


如果rs.Fields(一个?? NCHARa ??)。value = a ?? Closeda ??然后

MyColour = a ?? ?? FFFFFFa ?? a ??这是白色的HTML

Else

MyColour = a ??其他一些有效的HTML颜色

结束如果


然后在您定义表格的HTML正文中添加以下内容:


a?| ..bgcolor =<%response.write(MyColour)% a?| a?| a?| a?| a?|

更新的方法是从CSS调用不同的风格

但仍然使用相同的技术。


这是我大约一年前开始学习ASP的第一篇文章,所以我希望它对你有所帮助!


干杯,

Pete

" altreed"写道:


>




我是ASP,HTML和iis。


我的asp代码正常运行,以便我可以从数据库中检索我想要的记录

。我可以将表格中的数据放在屏幕上。

一切正常。


我希望评估记录中的一个字段并根据值

在该字段中我希望更改表格中行的颜色。在状态检查中为




我的DB字段是NCHAR。


我需要能够做这样的事情....


IF rs.statusoferror =" Closed"然后

response.write它的工作原理

结束如果


我找不到回复真实的方法 - rs .statusoferror =" Closed"

这就像数据类型与我的变量不兼容。如果我

将rs.statusoferror写入屏幕,它会出现 - 已关闭,但是我不能用相同的文字评估



我试过CAST,但未成功。我在错误的树上吠叫吗?


欢呼任何帮助。


Dave


" altreed" < ca ************* @ hotmail.comwrote in message

news:11 ***************** *****@i42g2000cwa.googlegr oups.com ...


IF rs.statusoferror =" Closed"然后

response.write它的工作原理

END IF



是rs记录集和statusoferror一个字段?


如果有,那么试试


如果rs(statusoferror)=封闭然后


>如果我

将rs.statusoferror写入屏幕,它会出现 - 已关闭,


你有没有试过


response.write" [" &安培; rs(statusoferror)& "]"


只是为了查看任何隐形字符?


你也可以试试


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


-

roger

" altreed" < ca ************* @ hotmail.comwrote in message

news:11 ***************** *****@i42g2000cwa.googlegr oups.com ...


>




我是ASP,HTML和iis的新手。


我的asp代码正常工作,以便我可以检索我想要的记录

来自数据库。我可以将表格中的数据放在屏幕上。

一切正常。


我希望评估记录中的一个字段并根据值

在该字段中我希望更改表格中行的颜色。在状态检查中为




我的DB字段是NCHAR。


我需要能够做这样的事情....


IF rs.statusoferror =" Closed"然后

response.write它的工作原理

结束如果


我找不到回复真实的方法 - rs .statusoferror =" Closed"

这就像数据类型与我的变量不兼容。如果我

将rs.statusoferror写入屏幕,它会出现 - 已关闭,但我

无法使用相同的文本进行评估。



您正在使用的语法(使用点运算符)将状态错误视为

它是记录集对象的方法或属性,它不是。这是一个

字段名称。


如果rs(statusoferror)=" Closed"然后

response.write它的工作原理

结束如果


您的代码应该抛出错误。你有错误继续下一页

在页面上方?如果是这样,请将其删除。它隐藏了有助于调试的错误信息。你用什么代码成功获得

已关闭用response.write出现在页面上?


-

Mike Brind



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

解决方案

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(a??NCHARa??).value = a??Closeda?? Then
MyColour = a??FFFFFFa?? a??This is white in HTML
Else
MyColour = a??some other valid HTML colour
End If

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

a?|..bgcolor = <% response.write(MyColour) %a?|a?|a?|a?|a?|

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


"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


"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


这篇关于评估记录集值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆