请看下面:
  Dim rs As New ADODB.Recordset  rs.Open "select sum(金额) from 进货记录 where 录单日期='" & dpdate.Value & "'", AdoCN, adOpenStatic, adLockPessimistic
  If rs.Fields(0).Value = Null Then
    lblTM(0).Caption = "0.00"
  Else
    lblTM(0).Caption = Format(rs.Fields(0).Value, "#,##0.00")
  End If
数据库为SQLSERVER2000 问题是这样的:  假设进货记录这个表里没有记录,也就是说这个语句中,SUM函数合计后,
  结果是rs.Fields(0).Value = Null(提示为:rs.Fields(0).Value = Null),此时rs.recordcount=1,
  但这个If rs.Fields(0).Value = Null Then语句并不能捕捉到这个条件,即转向了
  ELSE后面的语句,如何解决?
  我试过这样:
  If rs.Fields(0).Value IS Null Then  不行,提示无对象
  If rs.recordcount = 1 Then 也不行,此时就为1,但字段值为NULL
  怎么样才能用IF THEN 语句捕捉到合计后的字段值为NULL?

解决方案 »

  1.   

    If isnull(rs.Fields(0).Value) = true Then...
      

  2.   

    Dim rs As New ADODB.Recordset  rs.Open "select sum(金额) from 进货记录 where 录单日期='" & dpdate.Value & "'", AdoCN, adOpenStatic, adLockPessimistic
      If rs.Fields(0).Value = 0 Then
        lblTM(0).Caption = "0.00"
      Else
        lblTM(0).Caption = Format(rs.Fields(0).Value, "#,##0.00")
      End If
      

  3.   

    If isnull(rs.Fields(0).Value) Then
    isnull函数可以判断一个值是否为空.
    is仅仅对nothing关键字,用is nothing可以阵对对象来判断.
    例如rs.
      

  4.   

    Dim rs As New ADODB.Recordsetrs.Open "select sum(金额) from 进货记录 where 录单日期='" & dpdate.Value & "'", AdoCN, adOpenStatic, adLockPessimistic
    if rs.recordcount=0 then
        lbltm(0).caption="0.00"
        lbltm(0).refresh
    else
        If is notnull(rs.Fields(0).Value) Then
            lblTM(0).Caption = Format(rs.Fields(0).Value, "#,##0.00")
            lbltm(0).refresh 
        Else
            lblTM(0).Caption = "0.00"
            lbltm(0).refresh
        end if
    End If
      

  5.   

    上面的If is notnull(rs.Fields(0).Value) Then
    这句改成
          if not isnull(rs.fields(0).value) then
      

  6.   

    if not isnull(rs.fields(0).value) then