if statement ... newbie

dpan

Active member
Joined
Nov 22, 2005
Messages
28
Programming Experience
Beginner
I'm having a hard time here is my code:
VB.NET:
If DataGridView1.CurrentCell.Value = "" Then
            Label1.Text = "empty"
        Else
            Label1.Text = DataGridView1.CurrentCell.Value
        End If

just tring to print empty if the feild is null
 
Not entirely sure, don't have access to an IDE at the moment but it might be worth trying:-

VB.NET:
If DataGridView1.CurrentCell.Value = DBNull.Value Then
            Label1.Text = "empty"
        Else
            Label1.Text = DataGridView1.CurrentCell.Value
        End If

Hope this helps.
 
I get this error:

Error 1 Operator '=' is not defined for types 'Object' and 'System.DBNull'. C:\Documents and Settings\David\My Documents\Visual Studio 2005\Projects\test\WindowsApplication2\WindowsApplication2\Form1.vb 47 12 WindowsApplication2
 
Just convert the '=' to 'Is'.

VB.NET:
[COLOR=Blue]If[/COLOR] DataGridView1.CurrentCell.Value [COLOR=Blue]Is[/COLOR] DBNull.Value [COLOR=Blue]Then[/COLOR]
     Label1.Text = "empty"
[COLOR=Blue]Else[/COLOR]
     Label1.Text = DataGridView1.CurrentCell.Value
[COLOR=Blue]End If[/COLOR]
 
Back
Top