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?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top