如何判断 DataGrid 的单元格中是否为空值

fufq 2005-07-09 12:35:00
从数据库读出数据显示再DataGrid单元格中,怎么判断是不是空值啊?因为数据库里边的某些数据是有null值。我试过了这个不行:
DataGrid1_CurrentCellChanged
If Trim(EduDataGrid1.Item(EduDataGrid1.CurrentRowIndex, 1)) <> ""
报错"从类型“DBNull”到类型“String”的强制转换无效。"

然后用这个也不行:
Len(Trim(EduDataGrid1.Item(EduDataGrid1.CurrentRowIndex, 1))) <> 0

鄙人初次接触VB.NET,请各位指教
...全文
542 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
fufq 2005-07-09
  • 打赏
  • 举报
回复
thanks
LionWangCity 2005-07-09
  • 打赏
  • 举报
回复
ISDBNull函数也可以
LionWangCity 2005-07-09
  • 打赏
  • 举报
回复
唉,同步操作,
楼上的做法--〉2楼
LionWangCity 2005-07-09
  • 打赏
  • 举报
回复
我的上个做法不对,
楼上的做法也无法判断这个Cell到底是DBNull还是空串。
正确的判断如下
IF not EduDataGrid1.Item(EduDataGrid1.CurrentRowIndex, 1) Is DBNull.Value then
蜗牛水里爬 2005-07-09
  • 打赏
  • 举报
回复
用这个IsDBNull(EduDataGrid1.Item(EduDataGrid1.CurrentRowIndex, 1))
返回值是返回一个 Boolean 值然后你自己判断可以了。
你不说我也忘了~以前写的列子找不到了
机器人 2005-07-09
  • 打赏
  • 举报
回复
Trim(EduDataGrid1.Item(EduDataGrid1.CurrentRowIndex, 1).ToString())
*************

加上这个就可以了。

注意:空串,Nothing,DBNull 的区别。

LionWangCity 2005-07-09
  • 打赏
  • 举报
回复
IF not EduDataGrid1.Item(EduDataGrid1.CurrentRowIndex, 1) is nothing then


end if



fufq 2005-07-09
  • 打赏
  • 举报
回复
UP一下,,
????????知道的回我一下啊

16,554

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧