如果某个时间字段为空时,就显示1900-1-1
可是我不想显示,怎么办呢。
就是说,如果不为空时,显示正确的时间,否则显示空字符
谢谢大家

解决方案 »

  1.   

    在SQL语句或者存储过程里判断
    使用case语句
    datetime = case datetime when datetime is null or datetime = '' then '' else datetime end
      

  2.   

    你总要绑开个dataset吧。这样。比如dataset的名是dt
    int reslut=dt.tables[0].rows.cout;
    for(int i=0;i<=reslut;i++)
    {if(System.conva...todatatime(dt.tables[0].rows[i][你时间所在的列].tostring)==你说为空的那个时间)
    dt.tables[0].rows[i][你时间所在的列]=null;}
      

  3.   

    象楼上说的string strTime = dt.Tables[0].Rows[i][你时间所在的列].ToString();strTime  == ""?"1900-1-1":strTime;
      

  4.   

    使用SQL的select case是最好的方法
      

  5.   

    1、问题出在你添加数据时,如果时间字段没有给值,数据库默认就会写入1900-1-1
    这样你读取的时候它就是1900-1-1了。
    2、如果数据里时间字段为空,如果你用datagrid直接绑定时,它就会显示1900-1-1
       这样你需要在datagrid的ItemDataBound事件中加入:
       Select Case e.Item.ItemType
                Case ListItemType.AlternatingItem, ListItemType.Item
                    Dim drv As DataRowView = e.Item.DataItem
                    Dim strTime As String = Convert.ToString(drv("时间字段"))
                    If strTime <> "" Then
                        e.Item.Cells("4").Text = strTime
                    End If
            End Selecthttp://www.soeye.cn