请大家帮帮忙,我在SQL有一个表,表中有一个LSRQ日期型字段,允许它为空值,并通过SQL存储语句查询,可在VB前台查询结果中,lsrq为空值的记录不能显示并提示“无效使用NULL”。请问怎样控制"

解决方案 »

  1.   


        你昨天的提问,表述得很清楚,我也回复了,告诉你当lsrq为null时,year(lsrq)会出错。请重新考虑查询条件。
      

  2.   

    你显示日期的控件如果是dtpicker的话,就要将该控件设成复选框形式,当为null时将dtpicker的复选框不选,不为null时才入日期。
      

  3.   

    我换了另一种方式查询测试,结果还是会有这个错误提示
    另一种方式:(我添加一个字段sfls字符型字段)
     select * from zszb where ((lhdh=@lhdh) and year(lsrq)=year(@cxrq) and month(lsrq)=month(@cxrq)) or ((lhdh=@lhdh) and (sfls='否'))order by lhdh
    昨天这种方式
     select * from zszb where ((lhdh=@lhdh) and year(lsrq)=year(@cxrq) and month(lsrq)=month(@cxrq)) or ((lhdh=@lhdh) and (lsrq is null))  order by lhdh
    两种查询在SQL测试中都可以通过(测试时,输入参数为实参),结果都相同,可是在VB中运行后,查询结果遇到LSRQ为空值则提示“无效使用NULL”。(lsrq有空值也有非空值呀)