当我如Rs("字段")读去一个字段的值,当这个这个字段的值为空是运行出错,抛出异常.我该怎样处理这种问题呢?我需要当出现这种问题的时候只返回空串,而不中断程序的运行

解决方案 »

  1.   

    我估计你这个字段的值不是空,而是NULL,
    如果是空:if Rs("字段")= "" then
    如果是NULL :if Rs("字段") = Null then
      

  2.   

    if isnull(Rs("字段"))=true then elseendif或者
    if isempty(Rs("字段"))=true thenelseendif
      

  3.   

    if isnull(Rs.Fields ("字段")) then
        text=""
    else
        text=rs.fields("")
    endif
      

  4.   

    = Null是不可以的,只能用IsNull()函数来判断
    If isnull(Rs("字段")) then
        If trim(Rs("字段"))="" then'是否空字符
            ……
        End if
    ElseEnd if
      

  5.   

    sorry,上面错了
    If isnull(Rs("字段")) thenElse
        If trim(Rs("字段"))="" then'是否空字符
            ……
        End if
    End if
      

  6.   

    先给字段加上一个空格,再截去空格就不会出错了, 用不到去判断,那样程序运行会减慢
    Trim(Rs("字段") & "")
      

  7.   

    同意楼上的;
    还可以通过将字段的长度判断,如果为0赋值为空! If AdodcCheckDetail.Recordset.Fields(9).ActualSize = 0 Then
           FrmCheck.TxtCAppendix.Text = ""
         Else
           FrmCheck.TxtCAppendix.Text = AdodcCheckDetail.Recordset.Fields(9)
         End If
      

  8.   

    有没有搞错,你有没有了解字段类型?默认值?如果它的默认值是NULL 那你就用ISNULL来判断,如果它是“”那你就因该判断“”,如果它是EMPTY那么你们就因该判断:ISEMPTY。去试试吧,做数据查询时首先要明白字段类型!
      

  9.   

    http://expert.csdn.net/Expert/topic/2351/2351901.xml?temp=.7641107