我数据库中有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++;但是提示超出数组界限!求高手解答下!在线等!
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++;但是提示超出数组界限!求高手解答下!在线等!
解决方案 »
- 电子秤程序,读数运行时突然关闭电子秤电源,程序报错,怎么处理
- C# winform 遍历控件,用反射机制,用代码执行控件的mouseDown事件
- 跨线程、夸类访问主线程控件
- C#中Form窗体背景色的设制
- 高分悬赏 代码:datalist做的图片组,怎样当鼠标停留在其某张图片上时,会在另外一个img 上面显示其图片(在客户端)
- 关于SQLDMO的问题,用SQLDMO创建表的时候怎样添加主键???
- sql 建表的问题 如何让一个表中的2个列都有唯一性啊!
- 如何能够获取到主板的芯片组型号和内存插槽信息
- 关于调用DLL函数的问题
- 一个简单的问题(送分)在线等。急。。
- 求助:C#调用DLL提示尝试读取或写入受保护的内存。这通常指示其他内存已损坏
- 请问在listbox中,如何用键盘上下选项
这句不对,TryParse返回的是bool类型
time="0000-00-00"
}else{
time = Convert.ToDateTime(dataGridView1.Rows[i].Cells[j].Value);
};
加个判断!