ACCESS数据库表中字段为“数字型”,如果其值为NULL时如何处理?
sxyid 2002-02-28 05:51:45 大家好,我碰到一个问题:
(1) temp表结构说明:dq--文本型,a_count、b_count、c_count、d_count均是数字型
(2) temp表中的数据说明:该表是一个临时表,其中有一些记录的a_count、b_count、c_count、d_count的值为Null(没有0至9的数字)
(3) 有以下几句代码
......
Set myred = mydb.OpenRecordset("temp")
myred.MoveFirst
Do Until myred.EOF
With myred
total1 = .Fields("a_count") + .Fields("b_count") + .Fields("c_count") + .Fields("d_count")
total2 = total2 + total1
strsql = "update temp set count1=" & total1 & " where dq=" & .Fields("dq")
mydb.Execute strsql
End With
myred.MoveNext
Loop
......
<1>当a_count、b_count、c_count、d_count之一有一个值为Null时,
运行total1 = .Fields("a_count") + .Fields("b_count") + .Fields("c_count") + .Fields("d_count")就出现错误:“实时错误94,无效使用Null”
<2>当a_count、b_count、c_count、d_count全部都是一个0至9的数字时,运行正常。
这是为什么?
另外,我想,在上述代码之前加入一些代码:即将temp表中a_count、b_count、c_count、d_count之一的值为Null的字段替换为0,这样代码如何写?(vfp中replace all a_count with 0 for ......这样的代码在VB中如何写?)