better syntax for following simple statement...

  • Thread starter Thread starter Stimp
  • Start date Start date
S

Stimp

I have a dataset, objDSet, returning one scalar value.

I am currently using the following...

Dim rRow As DataRow = objDSet.Tables(0).Rows(0)

If rRow("UserCount") <> 0 Then (do something)

but I would prefer to put it all on one line if possible...

e.g.

If objDSet.Tables(0).Rows("UserCount") ...

is this possible?
 
Of course you can. You can do something like:

If objDSet.Tables(0).Rows(0)("UserCount") <> 0 Then ...

This implies you have option strict off, since you are getting an Object out
of the datarow, but you are comparing it to 0. You should always turn
option strict on, and make it the default for any new projects.
 
Of course you can. You can do something like:

If objDSet.Tables(0).Rows(0)("UserCount") <> 0 Then ...

This implies you have option strict off, since you are getting an Object out
of the datarow, but you are comparing it to 0. You should always turn
option strict on, and make it the default for any new projects.

so it's not possible to do with Option Strict On though?


 
You can, you just have to explicity cast the result to an integer.

In general, having Option Strict Off is a very bad programming practice. It
leads to many runtime errors that could have been caught at compile time. It
also makes code harder to read.

Stimp said:
Of course you can. You can do something like:

If objDSet.Tables(0).Rows(0)("UserCount") <> 0 Then ...

This implies you have option strict off, since you are getting an Object
out
of the datarow, but you are comparing it to 0. You should always turn
option strict on, and make it the default for any new projects.

so it's not possible to do with Option Strict On though?
 
Back
Top