是否可以编辑从记录集中抓取的数据?就我而言,我试图将数量加在一起,以便得到总数。因此,我正在尝试做的一个例子是:
<%
set rs = server.CreateObject("ADODB.recordset")
totalqty = 0
do NOT while rs.EOF
totalqty = totalqty + rs("QTY")
loop
>%
每当我尝试做这样的事情时,我总是会收到“类型不匹配”错误,我不确定如何解决这个问题。
一如既往,我们将不胜感激。
最佳答案
尝试像这样“转换”记录集中的值:
CDbl( rs.fields("QTY").value )
这会将值转换为 double 值。如果该值为空,您将收到错误消息,因此您必须先检查...
或者您可以编写一个函数来始终获取正确的类型:
public function parse(value, alternative)
dim val
val = trim(value & "")
parse = alternative
if val = "" then exit function
on error resume next
select case varType(parse)
case 2, 3 'integer, long
parse = cLng(val)
case 4, 5 'single, double
parse = cdbl(val)
case 6 'currency
parse = ccur(val)
case 7 'date
parse = cDate(val)
case 11 'bool
parse = cBool(val)
case 8 'string
parse = value & ""
case else
on error goto 0
lib.throwError("type not supported. val:" & value & " alt:" & alternative)
end select
on error goto 0
end function
dim val : val = rs("QTY")
val = parse(val, 0)
' now val is always an integer (either the value from db or 0)
关于html - 编辑从记录集中抓取的数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11561399/