检查列是否为空

编程入门 行业动态 更新时间:2024-10-09 23:13:45
本文介绍了检查列是否为空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在寻找如何检查特定行的列数据。我发现这个:

对于每一行在tablePiglet.Rows' - 数据表如果不是DBNull.Value.Equals (row(CurrentLocation))然后 MessageBox.Show(Not Empty)否则 MessageBox.Show(Empty)结束如果

我试图运行应用程序,代码不执行。我在 For Each 中添加了一个断点,但它刚刚结束。这是为什么?在CurrentLocation字段上还有一个数据,因此它应该显示为空。

我想要的是检查该行的 CurrentLocation 是否为空。 类似: SELECT CurrentLocation FROM tableFoo WHERE id = 1 然后检查它是否为空。 上面的代码是否正确?

解决方案

如果你知道你只有一行,而你知道它,因为在你的db

SELECT CurrentLocation FROM tableFoo WHERE id = 1

在这种情况下,你不需要循环,你知道,这是一行

如果tablePiglet.Rows.Count> 0 Then 如果IsDbNull(tablePiglet.Rows(0)(CurrentLocation))然后 MessageBox.Show(Empty)否则 MessageBox.Show )结束如果结束如果

>

但如果你确实有很多行,请创建List

Dim l作为新的List(of String) 对于i在tablePiglet.Rows.count-1中的整数= 0 如果IsDbNull(tablePiglet.Rows(i)(CurrentLocation ))然后 l.Add(i.ToString()) end if next 如果l.Count> 0 Then MessageBox.Show(Empty rows are& string.Join(,,l.ToArray())

它将列出所有具有空CurrentLocation

的行

I am looking on how to check the column data of a specific row. I found this:

For Each row In tablePiglet.Rows ' - data table If Not DBNull.Value.Equals(row("CurrentLocation")) Then MessageBox.Show("Not Empty") Else MessageBox.Show("Empty") End If Next

I tried to run the app, and the code does not execute. I added a breakpoint in For Each but it just ended. Why is that? There had been yet a data on CurrentLocation field, so it should display empty.

What I want is to check whether that row's CurrentLocation is empty or not. Something like : SELECT CurrentLocation FROM tableFoo WHERE id=1 then check if its empty or not. Is the code above the right thing to do? Or are there other better ways?

解决方案

If you know that you only have a single row, and you know it because in your db only one row may have a certain id as you pointed here

SELECT CurrentLocation FROM tableFoo WHERE id=1

In this case you don't need to loop, you KNOW, this is a single row

If tablePiglet.Rows.Count > 0 Then If IsDbNull(tablePiglet.Rows(0)("CurrentLocation")) Then MessageBox.Show("Empty") Else MessageBox.Show("Not Empty") End If End If

That should do it

But if you do have many rows, ok, create List

Dim l as new List(of String) For i as integer = 0 in tablePiglet.Rows.count-1 If IsDbNull(tablePiglet.Rows(i)("CurrentLocation")) Then l.Add(i.ToString()) end if next if l.Count > 0 Then MessageBox.Show("Empty rows are " & string.Join(",", l.ToArray())

It will list all the rows with empty "CurrentLocation"

更多推荐

检查列是否为空

本文发布于:2023-10-18 15:24:51,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1504623.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:为空

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!