在ASP中计算字段 [英] Calculating field in ASP

查看:89
本文介绍了在ASP中计算字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用于跟踪捐助者承诺的Access数据库。在其中,有一个

表,其中包含每个捐赠者的三个字段:Gift_Amount,Gift_Per_Year,

和Matching_Gift_Ratio。


以下公式将计算每个

捐赠者的总质押金额:

(Gift_Amount * Gift_Per_Year)*(Matching_Gift_Ratio + 1)。


所有捐赠者的总承诺只是总结计算值。


我的目标是创建一个能够显示承诺总额的ASP。这里

是我到目前为止创建的ASP:


******************* ****************************

< html>

< head>

< title> Pledge Totals< / title>

< / head>

< body bgcolor =" white" text =" black">

<%

''维度变量

Dim adoCon''保存数据库连接对象

Dim rsGiving''保存数据库中记录的记录集

Dim strSQL''保存数据库的SQL查询

Dim totalamt''持有总保证金额,一个计算字段

点心美元''持有格式化货币金额


''创建一个ADO连接odject

设置adoCon = Server.CreateObject(" ADODB.Connection")

''使用无DSN设置与Connection对象的活动连接

connection

adoCon.Open" DRIVER = {Microsoft Access Driver(* .mdb)}; DBQ = QUOT; &

Server.MapPath(" Careathon_SP2004.mdb")

''使用DSN连接设置与Connection对象的活动连接

''adoCon.Open" Careathon_SP2004"


''创建ADO记录集对象

设置rsGiving = Server.CreateObject(" ADODB .Recordset")


''使用SQL语句初始化strSQL变量以查询数据库

strSQL =" SELECT Giving.Gift_Amount,Giving.Gifts_Per_Year ,

Giving.Matching_Gift_Ratio from Giving WHERE Gift_Amount> 0 AND

Gifts_Per_Year> 0"


''打开记录集SQL查询

rsGiving.Open strSQL,adoCon


''循环记录集

Do while not rsGiving.EOF


''计算捐助者承诺总额并增加累计总额 - 这就是

代码存储和错误发生

totalamt =总量a mt +((rsGiving(" Gift_Amount))*

rsGiving(" Gifts_Per_Year"))*(rsGiving(" Matching_Gift_Ratio")+ 1))


''移动到记录集中的下一条记录

rsGiving.MoveNext


循环


' '格式化总金额

''设置美元= FormatCurrency(totalamt,2,-1,0,1)


''写HTML显示总质押金额

Response.Write(< br> $")

''Response.Write(美元)

Response.Write(totalamt)

Response.Write("< br>")

''重置服务器对象

rsGiving.Close

设置rsGiving = Nothing

Set adoCon = Nothing

Set totalamt = Nothing

Set dollar = Nothing

%>

< / body> ;

< / html>

**************************** ******************


但是,当我运行此页面时,我收到以下错误:


错误类型:

Microsoft VBScript运行时(0x800A000D)

类型不匹配


它出现在行上计算。


为了使这个页面正常工作,我需要更改什么?

I have an Access database used to track donor pledges. In it, there is a
table that contains three fields for each donor: Gift_Amount, Gift_Per_Year,
and Matching_Gift_Ratio.

The following formula would calculate the total pledge amount for each
donor:
(Gift_Amount * Gift_Per_Year) * (Matching_Gift_Ratio + 1).

A total Pledge for all donors would just sum up the calculated values.

My goal is to create an ASP that would show this total amount pledged. Here
is the ASP that I have created so far:

***********************************************
<html>
<head>
<title>Pledge Totals</title>
</head>
<body bgcolor="white" text="black">
<%
''Dimension variables
Dim adoCon ''Holds the Database Connection Object
Dim rsGiving ''Holds the recordset for the records in the database
Dim strSQL ''Holds the SQL query for the database
Dim totalamt ''Holds the Total Pledge amount, a calculated field
Dim dollars ''Holds the formated currency amount

''Create an ADO connection odject
Set adoCon = Server.CreateObject("ADODB.Connection")

''Set an active connection to the Connection object using a DSN-less
connection
adoCon.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" &
Server.MapPath("Careathon_SP2004.mdb")

''Set an active connection to the Connection object using DSN connection
''adoCon.Open "Careathon_SP2004"

''Create an ADO recordset object
Set rsGiving = Server.CreateObject("ADODB.Recordset")

''Initialise the strSQL variable with an SQL statement to query the database
strSQL = "SELECT Giving.Gift_Amount, Giving.Gifts_Per_Year,
Giving.Matching_Gift_Ratio FROM Giving WHERE Gift_Amount>0 AND
Gifts_Per_Year>0"

''Open the recordset with the SQL query
rsGiving.Open strSQL, adoCon

''Loop through the recordset
Do While not rsGiving.EOF

''Calculate total donor pledge and add to cumulative total - THIS IS WHERE
THE CODE STOPS AND THE ERROR OCCURS
totalamt = totalamt + ((rsGiving("Gift_Amount") *
rsGiving("Gifts_Per_Year")) * (rsGiving("Matching_Gift_Ratio") + 1))

''Move to the next record in the recordset
rsGiving.MoveNext

Loop

''Formats the total amount to currency
''set dollars = FormatCurrency(totalamt, 2, -1, 0, 1)

''Write the HTML to display the total pledge amount
Response.Write ("<br> $ ")
''Response.Write (dollars)
Response.Write (totalamt)
Response.Write ("<br>")
''Reset server objects
rsGiving.Close
Set rsGiving = Nothing
Set adoCon = Nothing
Set totalamt = Nothing
Set dollars = Nothing
%>
</body>
</html>
**********************************************

However, when I run this page, I get the following error:

Error Type:
Microsoft VBScript runtime (0x800A000D)
Type mismatch

It occurs on the line with the calculations.

What do I need to change in order for this page to work correctly?

推荐答案

")

''Response.Write(美元)

Response.Write(totalamt)

Response.Write (< br>")

''重置服务器对象

rsGiving.Close

设置rsGiving = Nothing

设置adoCon = Nothing

Set totalamt = Nothing

设置美元=没有

%>

< / body>

< / html>

************************************* *********


但是,当我运行此页面时,我收到以下错误:


错误类型:

Microsoft VBScript运行时(0x800A000D)

类型不匹配


它出现在计算行上。


为了使这个页面正常工作,我需要更改什么?

")
''Response.Write (dollars)
Response.Write (totalamt)
Response.Write ("<br>")
''Reset server objects
rsGiving.Close
Set rsGiving = Nothing
Set adoCon = Nothing
Set totalamt = Nothing
Set dollars = Nothing
%>
</body>
</html>
**********************************************

However, when I run this page, I get the following error:

Error Type:
Microsoft VBScript runtime (0x800A000D)
Type mismatch

It occurs on the line with the calculations.

What do I need to change in order for this page to work correctly?


为什么不呢:


SELECT DonorID,((Gift_Amount * Gift_Per_Year)*(Matching_Gift_Ratio + 1))

FROM TableName


AND


SELECT SUM(GiftAmount)FROM TableName


运行这两个查询,您不必在ASP中计算。


注意:我一般是针对SQL Server开发的(MSDE也可以接受)或者是
Oracle,而不是Access,所以你可能需要调整SQL。


-

Gregory A. Beamer

MVP; MCP:+ I,SE,SD,DBA


**************************** ********************** ********************

在盒子外面思考!

************************************* ************* ********************

< tp ****** @ kc.rr.com>在消息中写道

新闻:Qx ******************* @ twister.rdc-kc.rr.com ...
Why not:

SELECT DonorID, ((Gift_Amount * Gift_Per_Year) * (Matching_Gift_Ratio + 1))
FROM TableName

AND

SELECT SUM(GiftAmount) FROM TableName

Run these two queries and you do not have to calculate in ASP.

NOTE: I generally develop against SQL Server (MSDE is also acceptable) or
Oracle, not Access, so you may have to tweak the SQL.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

************************************************** ********************
Think Outside the Box!
************************************************** ********************
<tp******@kc.rr.com> wrote in message
news:Qx*******************@twister.rdc-kc.rr.com...
我有一个用于跟踪捐助者承诺的Access数据库。在其中,有一个
表,其中包含每个捐赠者的三个字段:Gift_Amount,
Gift_Per_Year和Matching_Gift_Ratio。

以下公式将计算每个捐赠的总承诺金额<捐赠者:
(Gift_Amount * Gift_Per_Year)*(Matching_Gift_Ratio + 1)。

所有捐赠者的总承诺只是总结计算值。
我的目标是创建一个能够显示承诺总额的ASP。
这是我到目前为止创建的ASP:

*************************** ********************
< html>
< head>
< title> Pledge Totals< / title>
< / head>
< body bgcolor =" white" text =" black">
<%
''维度变量
Dim adoCon''保存数据库连接对象
Dim rsGiving''保存记录的记录集在数据库中
Dim strSQL''持有数据库的SQL查询
Dim totalamt''持有总保证金额,计算字段
Dim dollar''持有格式化货币数量

''创建ADO连接odject
设置adoCon = Server.CreateObject(" ADODB.Connection")
'''使用Connection对象设置活动连接无DSN
连接
adoCon.Open" DRIVER = {Microsoft Access Driver(* .mdb)}; DBQ = QUOT; &
Server.MapPath(" Careathon_SP2004.mdb")
''使用DSN连接设置与Connection对象的活动连接
''adoCon.Open" Careathon_SP2004" ;'
''创建一个ADO记录集对象
设置rsGiving = Server.CreateObject(" ADODB.Recordset")
''初始化strSQL变量用于查询
数据库的SQL语句strSQL =" SELECT Giving.Gift_Amount,Giving.Gifts_Per_Year,
Giving.Matching_Gift_Ratio from Giving WHERE Gift_Amount> 0 AND
Gifts_Per_Year> 0"
< br'>''用SQL查询打开记录集
rsGiving.Open strSQL,adoCon

''循环记录集
尽管不是rsGiving.EOF

''计算总捐助者承诺并增加累积总额 - 这就是代码存储和错误发生的地方
totalamt = totalamt +((rsGiving(" Gift_Amount))*
rsGiving(" Gifts_Per_Year") )*(rsGiving(Matching_Gift_Ratio)+ 1))
''移动到记录集中的下一条记录
rsGiving.MoveNext

循环

''格式化总金额
''设置美元= FormatCurrency(totalamt,2,-1,0,1)

''将HTML写入显示总质押金额
Response.Write(" br>
I have an Access database used to track donor pledges. In it, there is a
table that contains three fields for each donor: Gift_Amount, Gift_Per_Year, and Matching_Gift_Ratio.

The following formula would calculate the total pledge amount for each
donor:
(Gift_Amount * Gift_Per_Year) * (Matching_Gift_Ratio + 1).

A total Pledge for all donors would just sum up the calculated values.

My goal is to create an ASP that would show this total amount pledged. Here is the ASP that I have created so far:

***********************************************
<html>
<head>
<title>Pledge Totals</title>
</head>
<body bgcolor="white" text="black">
<%
''Dimension variables
Dim adoCon ''Holds the Database Connection Object
Dim rsGiving ''Holds the recordset for the records in the database
Dim strSQL ''Holds the SQL query for the database
Dim totalamt ''Holds the Total Pledge amount, a calculated field
Dim dollars ''Holds the formated currency amount

''Create an ADO connection odject
Set adoCon = Server.CreateObject("ADODB.Connection")

''Set an active connection to the Connection object using a DSN-less
connection
adoCon.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" &
Server.MapPath("Careathon_SP2004.mdb")

''Set an active connection to the Connection object using DSN connection
''adoCon.Open "Careathon_SP2004"

''Create an ADO recordset object
Set rsGiving = Server.CreateObject("ADODB.Recordset")

''Initialise the strSQL variable with an SQL statement to query the database strSQL = "SELECT Giving.Gift_Amount, Giving.Gifts_Per_Year,
Giving.Matching_Gift_Ratio FROM Giving WHERE Gift_Amount>0 AND
Gifts_Per_Year>0"

''Open the recordset with the SQL query
rsGiving.Open strSQL, adoCon

''Loop through the recordset
Do While not rsGiving.EOF

''Calculate total donor pledge and add to cumulative total - THIS IS WHERE
THE CODE STOPS AND THE ERROR OCCURS
totalamt = totalamt + ((rsGiving("Gift_Amount") *
rsGiving("Gifts_Per_Year")) * (rsGiving("Matching_Gift_Ratio") + 1))

''Move to the next record in the recordset
rsGiving.MoveNext

Loop

''Formats the total amount to currency
''set dollars = FormatCurrency(totalamt, 2, -1, 0, 1)

''Write the HTML to display the total pledge amount
Response.Write ("<br>


")
''Response.Write(美元)
响应.Write(totalamt)
Response.Write("< br>")

''重置服务器对象
rsGiving.Close
设置rsGiving = Nothing
设置adoCon = Nothing
设置totalamt = Nothing
设置美元=没有
%>
< / body>
< / html>
**********************************************

然而,当我运行此页面时,我收到以下错误:

错误类型:
Microsoft VBScript运行时(0x800A000D)
类型不匹配

它发生在计算的界限。

为了使这个页面正常工作,我需要更改什么?
")
''Response.Write (dollars)
Response.Write (totalamt)
Response.Write ("<br>")
''Reset server objects
rsGiving.Close
Set rsGiving = Nothing
Set adoCon = Nothing
Set totalamt = Nothing
Set dollars = Nothing
%>
</body>
</html>
**********************************************

However, when I run this page, I get the following error:

Error Type:
Microsoft VBScript runtime (0x800A000D)
Type mismatch

It occurs on the line with the calculations.

What do I need to change in order for this page to work correctly?



这篇关于在ASP中计算字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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