我数据库中有datetime数据,可空的,做一个到期提醒,但是提醒时会出现DBNULL错误,我是这样写的
DateTime nowtime = DateTime.Now;
                            DateTime time = Convert.ToDateTime(dataGridView1.Rows[i].Cells[j].Value);
                            TimeSpan ts1 = new TimeSpan(nowtime.Ticks);
                            TimeSpan ts2 = new TimeSpan(time.Ticks);                            if (ts2 < ts1)
                            {
                                this.dataGridView1.Rows[i].Cells[j].Style.BackColor = Color.Red;
                            }
然后我用tryparse,
DateTime t3;
                            DateTime nowtime = DateTime.Now;
                            DateTime time = DateTime.TryParse(Convert.ToDateTime(dataGridView1.Rows[i].Cells[j].Value).ToString(),out t3);
                            TimeSpan ts1 = new TimeSpan(nowtime.Ticks);
                            TimeSpan ts2 = new TimeSpan(time.Ticks);                            if (ts2 < ts1)
                            {
                                this.dataGridView1.Rows[i].Cells[j].Style.BackColor = Color.Red;
                            }
提示无法从类型“bool”隐士转换为system。datetime,
这该如何解决呢 
我本来是想先判断 如果单元格中的值为null就跳过 就是i++;但是提示超出数组界限!求高手解答下!在线等!

解决方案 »

  1.   

    Convert.ToDateTime(dataGridView1.Rows[i].Cells[j].Value);这里面有bool类型的数据被,true或者false 这样的怎么转成2011-02-02这样的,数据类型都不一致,天方夜谭
      

  2.   

    晕死,bool类型还转个毛啊,直接更新数据库吧
      

  3.   

    读数据的时候加个条件不就可以了datetime is not null   治根了吧
      

  4.   

    DateTime time = DateTime.TryParse(Convert.ToDateTime(dataGridView1.Rows[i].Cells[j].Value).ToString(),out t3);
    这句不对,TryParse返回的是bool类型
      

  5.   

    bool flag = DateTime.TryParse(Convert.ToDateTime(dataGridView1.Rows[i].Cells[j].Value).ToString(),out t3);
      

  6.   

    if(dataGridView1.Rows[i].Cells[j].Value) {
    time="0000-00-00"
    }else{
    time = Convert.ToDateTime(dataGridView1.Rows[i].Cells[j].Value);
    };
    加个判断!
      

  7.   

    这个直接try抛出异常就实现功能了吧。