Question

I have a statement in VB.net that I thought I wrote correctly to prevent the second half from being evaluated. It looks like this:

If ((myDataSet2 IsNot Nothing) Or myDataSet2.Tables("CurData").Rows.Count > 0)

However it does not skip the second expresion "myDataSet2.Tables("CurData").Rows.Count > 0" like I want it to.

What should I change?

Was it helpful?

Solution

Use the OrElse operator.

If myDataSet2 IsNot Nothing OrElse myDataSet2.Tables("CurData").Rows.Count > 0

EDIT: See my comment on your original question. You are PROBABLY looking for:

If myDataSet2 IsNot Nothing AndAlso myDataSet2.Tables("CurData").Rows.Count > 0

That will check if myDataSet2 isn't null. Assuming that it's not, it will then check that there is at least one row. If it is null, then the second condition won't be checked.

OTHER TIPS

You need to put the second statement into the first if-clause.

Like this:

If(statement1) then
   If(statemtent2) then
   Else
   End if
Else
End If

As it is now both are evaluated and if one of them is true the content in your if-clause will be executed.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top