select (select sum(money) from weblog where  convert(varchar(7),buy_time,120)=convert(varchar(7),getdate(),120)) as theM,
(select sum(money) from weblog where  convert(varchar(10),buy_time,120)=convert(varchar(10),getdate(),120) ) as theday,
(select sum(money) from weblog where  convert(varchar(10),buy_time,120)=convert(varchar(10),dateadd(month,-1,getdate()),120) ) as lastM上面的数据库分别取出theM,theday,lastM并在VS.NET中从   myread = mycmd.ExecuteReader
        If myread.Read Then
 theM.Text = myread("theM")
         today.Text = myread("theday")
            onM.Text = myread("lastM")当其中取的任何一个值为空时,页面就会报错,无法将NULL转换成string,请问各位,应该怎么办呢?

解决方案 »

  1.   

    if( myread("theday")==dbnull.value)
    {
       //为null
    }
    else
    }
      //不为null
    }
      

  2.   

    vb.net 
    if myread("theday")==null then
       //为null
    else
      //不为null
    endif
      

  3.   

    用isDBNULL(myread("theM"))判斷一下
    可以寫個function 
    當數據不為空時傳會原數據  
    為空就傳會想要的數據
      

  4.   

    也可以myread("theM")&""
    或者在sql語句里 用 isnull
      

  5.   

    myread("theday") != null?myread("theday"):""
    上面的代码意思是: 
    如果myread("theday")的值不是为空那么值就是myread("theday"),为空则用值为""
      

  6.   

    在SQL里面写个IsNull(字段名,'')