tags:

views:

200

answers:

3
 Dim xbg As Rm

xbg.LobId = cmb_lob.SelectedValue
xbg.Mobile = mobno.Text
xbg.BusinessFax = faxno.Text
xbg.BusinessPhone = phno.Text
xbg.Save()

I have a combo box, which is not mandatory while input in the module. therefore user can select blank value in combo cox for which i want to save null in Oracle Database for that record. I had trid with following condition but fails to get result. you are requested to please help

if cmb_lob.selectedindex=-1 then 
    xbg.lob=dbnull 
else 
    xbg.LobId = cmb_lob.SelectedValue

Actual Problem arises when first user save record with selection in Combo box then user edit that record and select blank from Combo box. now i have to replace value of combox box with null at database.

A: 

try:

if cmb_lob.selectedindex <> -1 then 
    xbg.LobId = cmb_lob.SelectedValue
else
    xbg.LobId = Nothing 'suggested by John Shean (see comments)

So that if the value is selected only then assign it to field else leave it as it is (null)

TheVillageIdiot
Actual Problem arises when first user save record with selection in Combo box then user edit that record and select blank from Combo box. now i have to replace value of combox box with null at database.
Faizan Dosani
any help appreciated
Faizan Dosani
please try DbNull.Value
TheVillageIdiot
THANKS ONCE AGAIN BUT XBG.LOB IS NUMERIC TYPE WHEN I DO THE FOLLOWING XBG.LOBID=DBNULL.VALUE , GETTING EXCEPTION OF INVALID TYPE CAST.
Faizan Dosani
Try xbg.LobId = Nothing instead
John Sheehan
:( C# vs VB.Net difference!
TheVillageIdiot
Thanks John its worked
Faizan Dosani
+1  A: 

Set it to null or whatever VB considers null - it will be set in the DB that way.

Rob Conery
A: 

Try xbg.LobId = Nothing instead – By John Sheehan

Faizan Dosani