6784
asked on
DBNULL
I need a way to test for Null values because my app. currently crashes on them
here is a portion of my code. I would need the test in here somewhere.
For Each li In ddlDefaultVatCode.Items
If li.Text.Substring(0, 3) = oDr!Vat_Code Then
li.Selected = True
Exit For
End If
Next
thanks
here is a portion of my code. I would need the test in here somewhere.
For Each li In ddlDefaultVatCode.Items
If li.Text.Substring(0, 3) = oDr!Vat_Code Then
li.Selected = True
Exit For
End If
Next
thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I don't think that example would work. Heres more info on what I am doing.
All my dropdownlists have already been populated. Now I am getting default values for a particular country code. When the two values match (database vs dropdownlist) that becomes the selected item. Is there away to make the null value act as any unmatched item and keep looping.
All my dropdownlists have already been populated. Now I am getting default values for a particular country code. When the two values match (database vs dropdownlist) that becomes the selected item. Is there away to make the null value act as any unmatched item and keep looping.
ASKER
For Each li In ddlDefaultVatCode.Items
If li.Text = DBNull Then
MsgBox("Null value!")
End If
If li.Text.Substring(0, 3) = oDr!Vat_Code Then
li.Selected = True
Exit For
End If
Next
Srcak
I don't think that example would work. Heres more info on what I am doing.
All my dropdownlists have already been populated. Now I am getting default values for a particular country code. When the two values match (database vs dropdownlist) that becomes the selected item. Is there away to make the null value act as any unmatched item and keep looping.
If li.Text = DBNull Then
MsgBox("Null value!")
End If
If li.Text.Substring(0, 3) = oDr!Vat_Code Then
li.Selected = True
Exit For
End If
Next
Srcak
I don't think that example would work. Heres more info on what I am doing.
All my dropdownlists have already been populated. Now I am getting default values for a particular country code. When the two values match (database vs dropdownlist) that becomes the selected item. Is there away to make the null value act as any unmatched item and keep looping.
I assume that you are using a combobox? If so:
For Each li In ddlDefaultVatCode.Items
If Not yourComboBox.Items.IndexOf (li.text) <> -1 Then ' "" is not a NULL
If li.Text.Substring(0, 3) = oDr!Vat_Code Then
li.Selected = True
Exit For
End If
Else
'Do what you want to do with Null values.
End If
Next
For Each li In ddlDefaultVatCode.Items
If Not yourComboBox.Items.IndexOf
If li.Text.Substring(0, 3) = oDr!Vat_Code Then
li.Selected = True
Exit For
End If
Else
'Do what you want to do with Null values.
End If
Next
ASKER
When I get a null value is there a way to keep the procedure going (looping)
when you say ''Do what you want to do with Null values.
I want the loop to continue but I don't know how to do it.
when you say ''Do what you want to do with Null values.
I want the loop to continue but I don't know how to do it.
The logic I gave you in my post, it is doing exactly what you want. We are not exiting from the FOR loop. It is just skipping the NULL values.
ASKER
sorry for not putting more info in the first place
the null value isn't comming from the listitem its comming from the database thats being queried
For Each li In ddlDefaultVatCode.Items
If Not yourComboBox.Items.IndexOf (li.text) <> -1 Then ' "" is not a NULL
If li.Text.Substring(0, 3) = oDr!Vat_Code Then ******this is null*********
li.Selected = True
Exit For
End If
Else
'Do what you want to do with Null values.
End If
Next
the null value isn't comming from the listitem its comming from the database thats being queried
For Each li In ddlDefaultVatCode.Items
If Not yourComboBox.Items.IndexOf
If li.Text.Substring(0, 3) = oDr!Vat_Code Then ******this is null*********
li.Selected = True
Exit For
End If
Else
'Do what you want to do with Null values.
End If
Next
then you could just do this:
For Each li In ddlDefaultVatCode.Items
If Not yourComboBox.Items.IndexOf (oDr!Vat_C ode) <> -1 Then
If li.Text.Substring(0, 3) = oDr!Vat_Code Then
li.Selected = True
Exit For
End If
Else
'Do what you want to do with Null values.
End If
Next
For Each li In ddlDefaultVatCode.Items
If Not yourComboBox.Items.IndexOf
If li.Text.Substring(0, 3) = oDr!Vat_Code Then
li.Selected = True
Exit For
End If
Else
'Do what you want to do with Null values.
End If
Next
lol... damn... I am such a fool.. it was understood... I don't know what I was thinking...
Ok.. try this..
For Each li In ddlDefaultVatCode.Items
If Not yourComboBox.Items.IndexOf (li.text) <> -1 Then ' "" is not a NULL
If Not IsDbNull(oDr!Vat_Code) And li.Text.Substring(0, 3) = oDr!Vat_Code Then
li.Selected = True
Exit For
End If
Else
'Do what you want to do with Null values.
End If
Next
Ok.. try this..
For Each li In ddlDefaultVatCode.Items
If Not yourComboBox.Items.IndexOf
If Not IsDbNull(oDr!Vat_Code) And li.Text.Substring(0, 3) = oDr!Vat_Code Then
li.Selected = True
Exit For
End If
Else
'Do what you want to do with Null values.
End If
Next
ASKER
Srcalc-
your suggestion produced an error of: System.InvalidCastExceptio n: Specified cast is not valid. I am guessing its talking about the second line
For Each li In ddlDefaultVatCode.Items
If Not yourComboBox.Items.IndexOf (oDr!Vat_C ode) <> -1 Then
If li.Text.Substring(0, 3) = oDr!Vat_Code Then
li.Selected = True
Exit For
End If
Else
'Do what you want to do with Null values.
End If
Next
DotNetLover__Baan
With yours I get this error: Value of type 'String' cannot be converted to 'System.Web.UI.WebControls .ListItem' .
Its talking about this: If Not yourComboBox.Items.IndexOf ****(li.te xt)******* <> -1 Then ' "" is not a NULL
I appreciate the help you guys
your suggestion produced an error of: System.InvalidCastExceptio
For Each li In ddlDefaultVatCode.Items
If Not yourComboBox.Items.IndexOf
If li.Text.Substring(0, 3) = oDr!Vat_Code Then
li.Selected = True
Exit For
End If
Else
'Do what you want to do with Null values.
End If
Next
DotNetLover__Baan
With yours I get this error: Value of type 'String' cannot be converted to 'System.Web.UI.WebControls
Its talking about this: If Not yourComboBox.Items.IndexOf
I appreciate the help you guys
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
This is what I came up with.
For Each li In ddlDefaultVatCode.Items
If (IsDBNull(oDr!Vat_Code)) = True Then
Exit For
Else
If li.Text.Substring(0, 3) = oDr!Vat_Code Then
li.Selected = True
Exit For
End If
End If
Next
I am going to split the points since you both added alot.
Thanks
For Each li In ddlDefaultVatCode.Items
If (IsDBNull(oDr!Vat_Code)) = True Then
Exit For
Else
If li.Text.Substring(0, 3) = oDr!Vat_Code Then
li.Selected = True
Exit For
End If
End If
Next
I am going to split the points since you both added alot.
Thanks
For Each li In ddlDefaultVatCode.Items
If Not IsDbNull(li.Text) And li.Text<>"" Then ' "" is not a NULL
If li.Text.Substring(0, 3) = oDr!Vat_Code Then
li.Selected = True
Exit For
End If
Else
'Do what you want to do with Null values.
End If
Next
-Baan