Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

VB 2008  - Is a DataGridView field null or empty?

Posted on 2009-07-10
11
457 Views
Last Modified: 2012-05-07
If a grid field does not contain data then Completed = False.  The fields to be tested may contain text, a numeric, a date, or nothing at all.  It is possible that some data was entered into one of the fields and then removed by the user.

How can I test that a Value exists?  The design-time compiler does not like the following statement.

If EvalItemsDataGridView.CurrentRow.Cells(i).Value() = Nothing Then Completed = False
0
Comment
Question by:ljcor
  • 5
  • 5
11 Comments
 
LVL 9

Expert Comment

by:wellhole
ID: 24826850
You will want to use "is nothing" instead of "= nothing".
0
 

Author Comment

by:ljcor
ID: 24826902
Unfortunately, it does not like  IsNothing  either.
0
 
LVL 9

Expert Comment

by:wellhole
ID: 24826907
2 words.......
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

Author Comment

by:ljcor
ID: 24826974
It doesn't like that either:  two words, two errors.

IS says: Expression expected

NOTHING says: Illegal call expression or index expression
0
 
LVL 9

Expert Comment

by:wellhole
ID: 24826983
Please post your code after the modification.
0
 

Author Comment

by:ljcor
ID: 24826994
       Dim Completed As Boolean = True
        For i As Integer = 0 To 8
            If EvalItemsDataGridView.CurrentRow.Cells(i).Value() = Is Nothing() Then Completed = False
        Next
        If Completed = False Then
            Call MsgBox("You cannot SELECT a Project until these data entry items are completed.  ", vbOKOnly + vbCritical + vbApplicationModal + vbDefaultButton1, "UNFINISHED DATA ENTRY")
            Exit Sub
        End If
0
 
LVL 9

Expert Comment

by:wellhole
ID: 24826995
REMOVE = and Nothing() is not a function so remove ()
0
 
LVL 3

Expert Comment

by:jbeasle3
ID: 24826996
Try this:
 
If EvalItemsDataGridView.CurrentRow.Cells(i).Value() = String.Empty Then Completed = False
OR
If EvalItemsDataGridView.CurrentRow.Cells(i).Value() = "" Then Completed = False
0
 

Author Comment

by:ljcor
ID: 24827048
I edited the data out of one of the fields:  The runtime error is:
   "Operator '=' is not defined for type 'DBNull' and string ""."
0
 
LVL 9

Accepted Solution

by:
wellhole earned 500 total points
ID: 24827069
Use isdbnull(EvalItemsDataGridView.CurrentRow.Cells(i).Value()) instead of comparing against an empty string.
0
 

Author Closing Comment

by:ljcor
ID: 31602249
YES!!  That worked perfectly.  Thanks for your help.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

837 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