检查是否存在2个数据库

时间:2016-04-21 17:59:38

标签: vb.net

这可能是一个新手问题但是如何检查两个数据表是否为空?如果一个数据表有记录而另一个没有做某事。或者,如果他们都有记录做某事。如果没有记录什么都不做。

If dt is nothing andalso dt.rows.count > 0 andalso dt2 is nothing andalso dt2.rows.count > 0 then 

    '  Process

End if

1 个答案:

答案 0 :(得分:3)

有时,将代码拆分为更简单的部分可能是避免复杂条件的解决方案

Dim firstEmptyOrNull = dt is Nothing OrElse dt.Rows.Length = 0
Dim secondEmptyOrNull = dt2 is Nothing OrElse dt2.Rows.Length = 0

If firstEmptyOrNull And secondEmptyOrNull Then
  ' Do nothing 
Else if Not firstEmptyOrNull And secondEmptyOrNull Then
  ' Code if the first table is good but not the second one
Else if firstEmptyOrNull And Not secondEmptyOrNull Then
  ' Code if the second table is good but not the first one
Else
  ' Code for both tables good
End If
相关问题