Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/37.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net 为什么我的if语句没有被触发_Asp.net_Vb.net - Fatal编程技术网

Asp.net 为什么我的if语句没有被触发

Asp.net 为什么我的if语句没有被触发,asp.net,vb.net,Asp.net,Vb.net,我做了一个简单的实验,以确保我知道发生了什么,因为我是一个编程新手。这让我很难堪,我对我的电脑撒谎很生气。:) 这是我的vb.net If table2.Rows.Count = 0 Then LBLCannary.Visible = True End If 现在,如果在调试期间将鼠标悬停在上面,它会告诉我计数为零。ie table2.Rows.Count 0,但由于某种奇怪的原因,如果,它永远不会转到中的下一行。如果桌子是空的。为什么不起作用 回答:愚蠢的新手错误,所有这些都是在返回

我做了一个简单的实验,以确保我知道发生了什么,因为我是一个编程新手。这让我很难堪,我对我的电脑撒谎很生气。:)

这是我的vb.net

If table2.Rows.Count = 0 Then
    LBLCannary.Visible = True
End If
现在,如果在调试期间将鼠标悬停在上面,它会告诉我计数为零。ie table2.Rows.Count 0,但由于某种奇怪的原因,如果
,它永远不会转到
中的下一行。如果桌子是空的。为什么不起作用


回答:愚蠢的新手错误,所有这些都是在返回后完成的,函数返回某些内容后不会发生任何事情。

你能试试相反的方法吗

If table2 IsNot Nothing AndAlso table2.Rows.Count > 0 Then
    'do nothing
Else
    'if no rows or if table is empty
    LBLCannary.Visible = True
End If
或者把你的情况扩大到

If table2 Is Nothing OrElse table2.Rows.Count < 1 Then

    LBLCannary.Visible = True
End If
如果table2为空或lese table2.Rows.Count<1,则
LBLCannary.Visible=True
如果结束

你能试试反过来吗

If table2 IsNot Nothing AndAlso table2.Rows.Count > 0 Then
    'do nothing
Else
    'if no rows or if table is empty
    LBLCannary.Visible = True
End If
或者把你的情况扩大到

If table2 Is Nothing OrElse table2.Rows.Count < 1 Then

    LBLCannary.Visible = True
End If
如果table2为空或lese table2.Rows.Count<1,则
LBLCannary.Visible=True
如果结束

是的,相反的方法能起作用,并产生预期的效果。前者仍然不起作用。你能试着按照建议扩大你的病情吗?很抱歉,我找到了答案,这是我自己愚蠢的新男友的错误。我在回归后做了所有这些,所以没有一件事情真正发生。是的,相反的效果很好,前者仍然不起作用。你能试着按照建议扩大你的病情吗?我很抱歉,我找到了答案,这是我自己愚蠢的新男友的错误。我在返回后做了所有这些,所以没有任何一个实际发生。可能是一个NullReferenceException,在调试时不能抛出。可能是一个NullReferenceException,在调试时不能抛出。