在VB6和SQL Server中,如何用语句判断一个子段的值为Null

解决方案 »

  1.   

    '引用ADO(Microsoft ActiveX Data Objects 2.X Library)
    Private Sub Command1_Click()
        On Error GoTo err
        Dim cn As New ADODB.Connection, rs
        '有密码的连接:
        'cn.ConnectionString = "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=登陆用户名;Password=登录密码;Initial Catalog=数据库名;Data Source=yourSERVICE"
        '无密码的连接:
        cn.ConnectionString = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=数据库名;Data Source=服务器别名"
        cn.Open
        rs.CursorLocation=adUseClient'设置客户端游标
        rs.Open "select * from 表1", cn, 3, 2
        If rs.Eof Then Exit Sub
        If IsNull(rs.fields(0)) Then
            Msgbox "字段值为空!"
        End If   
        Exit Sub
    err:
        MsgBox err.Description
    End Sub
      

  2.   

    if Trim(rs(0) &"")="" then
       msgbox "字段为空"
    end if
      

  3.   

    在vb中
      if isnull(rs(0)) then
         msgbox "字段为空"
      end if
    在sql语句中
      sum(case when je<>'' then je else 0 end )
      

  4.   

    ISNULL也可以用在查询句子里。