?
Solved

VB and a disrespect for NULL?

Posted on 2007-07-25
9
Medium Priority
?
190 Views
Last Modified: 2013-11-26
Is this the best way to limit a NULL problem in vb.net?  I consider it really STUPID to deal with a potential null like this.  C# rules and vb,,,,,  Bad Steve.


For Each oRow As DataGridViewRow In dgRollover.Rows
            If oRow.Cells(0).Value Is Nothing Or DBNull.Value.Equals(oRow.Cells(0).Value) Then
            Else

                If oRow.Cells(0).Value = 1 Then
                    ii = ii + 1
                    'MessageBox.Show(" ID # " & oRow.Cells(3).Value & " presented")
                    CCProcess.RollTransaction(oRow.Cells(3).Value, Me.DateTimePicker1.Value)

Cell(0) is a checkBox in the grid and it it preseted in DATA as a 0 from the server.  

So is there a better way in VB that I am mising?

TIA
 
0
Comment
Question by:srussell705
  • 3
  • 3
  • 3
9 Comments
 
LVL 48

Expert Comment

by:jpaulino
ID: 19567884
you can use If String.IsNullorEmpty(oRow.Cells(0).Value) Then
0
 
LVL 1

Author Comment

by:srussell705
ID: 19568277
Thanks for the reply.

This is an INT column so will that work?  

This column is a checkbox populated with 0 in the data pull from the backend.

0
 
LVL 6

Expert Comment

by:ToFro
ID: 19568321
You could have used "Not"-keywords and the "And"-operator to leave out the empty if block like this:

If Not oRow.Cells(0).Value Is Nothing And Not DBNull.Value.Equals(oRow.Cells(0).Value) Then
   If oRow.Cells(0).Value = 1 Then
                    ii = ii + 1
   ...
   End If
End If

I'm not sure if that's what you meant. Or do you perhaps just dislike the keyword (Nothing)?
0
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 
LVL 6

Expert Comment

by:ToFro
ID: 19568340
If oRow.Cells(0).Value Is Nothing Or DBNull.Value.Equals(oRow.Cells(0).Value) Then
   ' By the empty if block I meant this block
Else
   If oRow.Cells(0).Value = 1 Then
                    ii = ii + 1
   ...
   End If
End If
0
 
LVL 1

Author Comment

by:srussell705
ID: 19569507

You could have used "Not"-keywords and the "And"-operator to leave out the empty if block like this:

If Not oRow.Cells(0).Value Is Nothing And Not DBNull.Value.Equals(oRow.Cells(0).Value) Then
   If oRow.Cells(0).Value = 1 Then
                    ii = ii + 1
   ...
   End If
End If

I'm not sure if that's what you meant. Or do you perhaps just dislike the keyword (Nothing)?

I'll go out on a limb and ask "What is the difference between Nothing and Null?"

Coming from C# it's perplexing that the allowed "nothing" to make it's way into VB.NET in the first place.  I'm sure it would have just toasted all your former code but Nothing is Something and Null is the absence of value.

So why do I have to test for either condition?  Is it a checkbox thing or am I missing the point.  
 
0
 
LVL 48

Expert Comment

by:jpaulino
ID: 19570264
Could not be the better way to do it but is how I do:

If oRow.Cells(0).Value.ToString  =  Then
 ' my code
End If
0
 
LVL 1

Author Comment

by:srussell705
ID: 19571507
jpaulino.  Thanks for the reply.

I'll check it out in the morning.  Something looks wrong because it's just to simple.  

This is an int column so I have to see it work.

0
 
LVL 6

Accepted Solution

by:
ToFro earned 300 total points
ID: 19571991
>> I'll go out on a limb and ask "What is the difference between Nothing and Null?"

Nothing is valid for both value and reference types, while null is only valid for reference types. When used as the value for reference types, I guess they are pretty much the same thing. Setting a value type to Nothing will actually set it to its default value.
0
 
LVL 48

Assisted Solution

by:jpaulino
jpaulino earned 75 total points
ID: 19576036
srussell705 is "" instead of . I have made copy paste! :-)

If oRow.Cells(0).Value.ToString  = "" Then
 ' my code
End If
0

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question