Operator '-' is not defined for type 'Double' and type 'DBNull'. [vb.net datagridview] -
here getting following bracketed error (operator '-' not defined type 'double' , type 'dbnull'.) when executing netvaluevalidation(). working in column of "discper" after executing discpervalidation()
private sub grdpurchase_cellendedit(byval sender object, byval e system.windows.forms.datagridviewcelleventargs) handles grdpurchase.cellendedit celledited = true currentcolumn = e.columnindex currentrow = e.rowindex if me.grdpurchase.columns(me.grdpurchase.currentcell.columnindex).name = "itemcode" if not me.grdpurchase.rows(e.rowindex).cells("itemcode").value dbnull.value seekitemdetails() end if else if me.grdpurchase.columns(me.grdpurchase.currentcell.columnindex).name = "packingratio" packingratiovalidation() elseif me.grdpurchase.columns(me.grdpurchase.currentcell.columnindex).name = "price" pricevalidation() netvaluevalidation() elseif me.grdpurchase.columns(me.grdpurchase.currentcell.columnindex).name = "grossamt" grossamtvalidation() 'netvaluevalidation() elseif me.grdpurchase.columns(me.grdpurchase.currentcell.columnindex).name = "kgs" kgsvalid() 'netvaluevalidation() elseif me.grdpurchase.columns(me.grdpurchase.currentcell.columnindex).name = "discper" discpervalidation() 'netvaluevalidation() end if sendkeys.send("{up}" + "{tab}") end if end sub private sub packingratiovalidation() if not me.grdpurchase.rows(me.grdpurchase.currentcell.rowindex).cells("packingratio").value dbnull.value , _ not me.grdpurchase.rows(me.grdpurchase.currentcell.rowindex).cells("packingratio_temp").value dbnull.value , _ not me.grdpurchase.rows(me.grdpurchase.currentcell.rowindex).cells("itemcode").value dbnull.value me.grdpurchase.rows(me.grdpurchase.currentcell.rowindex).cells("qty").value = _ me.grdpurchase.rows(me.grdpurchase.currentcell.rowindex).cells("packingratio").value * _ me.grdpurchase.rows(me.grdpurchase.currentcell.rowindex).cells("packingratio_temp").value end if end sub private sub pricevalidation() if not me.grdpurchase.rows(me.grdpurchase.currentcell.rowindex).cells("itemcode").value dbnull.value , _ not me.grdpurchase.rows(me.grdpurchase.currentcell.rowindex).cells("qty").value dbnull.value , _ not me.grdpurchase.rows(me.grdpurchase.currentcell.rowindex).cells("price").value dbnull.value me.grdpurchase.rows(me.grdpurchase.currentcell.rowindex).cells("grossamt").value = me.grdpurchase.rows(me.grdpurchase.currentcell.rowindex).cells("price").value * _ me.grdpurchase.rows(me.grdpurchase.currentcell.rowindex).cells("qty").value end if end sub private sub grossamtvalidation() if not me.grdpurchase.rows(me.grdpurchase.currentcell.rowindex).cells("itemcode").value dbnull.value , _ not me.grdpurchase.rows(me.grdpurchase.currentcell.rowindex).cells("qty").value dbnull.value , _ not me.grdpurchase.rows(me.grdpurchase.currentcell.rowindex).cells("grossamt").value dbnull.value me.grdpurchase.rows(me.grdpurchase.currentcell.rowindex).cells("price").value = me.grdpurchase.rows(me.grdpurchase.currentcell.rowindex).cells("grossamt").value / _ me.grdpurchase.rows(me.grdpurchase.currentcell.rowindex).cells("qty").value end if end sub private sub kgsvalid() if not me.grdpurchase.rows(me.grdpurchase.currentcell.rowindex).cells("itemcode").value dbnull.value , _ not me.grdpurchase.rows(me.grdpurchase.currentcell.rowindex).cells("qty").value dbnull.value , _ not me.grdpurchase.rows(me.grdpurchase.currentcell.rowindex).cells("price").value dbnull.value , _ not me.grdpurchase.rows(me.grdpurchase.currentcell.rowindex).cells("grossamt").value dbnull.value me.grdpurchase.rows(me.grdpurchase.currentcell.rowindex).cells("kgrate").value = me.grdpurchase.rows(me.grdpurchase.currentcell.rowindex).cells("grossamt").value / _ me.grdpurchase.rows(me.grdpurchase.currentcell.rowindex).cells("kgs").value end if end sub private sub discpervalidation() if not me.grdpurchase.rows(me.grdpurchase.currentcell.rowindex).cells("itemcode").value dbnull.value , _ not me.grdpurchase.rows(me.grdpurchase.currentcell.rowindex).cells("grossamt").value dbnull.value , _ not me.grdpurchase.rows(me.grdpurchase.currentcell.rowindex).cells("discper").value dbnull.value me.grdpurchase.rows(me.grdpurchase.currentcell.rowindex).cells("discamt").value = _ (me.grdpurchase.rows(me.grdpurchase.currentcell.rowindex).cells("grossamt").value / 100) * _ me.grdpurchase.rows(me.grdpurchase.currentcell.rowindex).cells("discper").value end if end sub private sub netvaluevalidation() if not me.grdpurchase.rows(me.grdpurchase.currentcell.rowindex).cells("itemcode").value dbnull.value , _ not me.grdpurchase.rows(me.grdpurchase.currentcell.rowindex).cells("grossamt").value dbnull.value me.grdpurchase.rows(me.grdpurchase.currentcell.rowindex).cells("netvalue").value = _ me.grdpurchase.rows(me.grdpurchase.currentcell.rowindex).cells("grossamt").value - _ me.grdpurchase.rows(me.grdpurchase.currentcell.rowindex).cells("discamt").value end if end sub
the message means in code:
me.grdpurchase.rows(me.grdpurchase.currentcell.rowindex).cells("grossamt").value - _ me.grdpurchase.rows(me.grdpurchase.currentcell.rowindex).cells("discamt").value
one of 2 cells dbnull
. based on message, cell involved in subtraction, these 2. odd thing else testing cell after cell dbnull
, not here.
not nothing, have lots , lots of unneeded code there makes hard see type of thing. instance big if block in cellendedit simplified like:
dim name string = dgv2.rows(e.columnindex).cells(e.columnindex).value.tostring select case name case "price" pricevalidation(e.rowindex) netvaluevalidation(...) case "grossamt" grossamtvalidation(...) end select
i'm not sure why arent using event args available. need pricevalidation
(passing row work on eventargs
):
private sub pricevalidation(r int32) ' note: doing pricing, not validation dim quan = safeconvert(dgv.rows(r).cells("qty").value) dim price = safeconvert(dgv.rows(r).cells("price").value) dgv.rows(r).cells("grossamt").value = (quan * price) end sub
i suspect option strict
not on -- should be:
grdpurchase.rows(...).cells("qty").value = _ grdpurchase.rows(...).cells("packingratio").value * _ grdpurchase.rows(...).cells("packingratio_temp").value
a cell value returns object, not number, code trying multiply 2 objects. simple procedure use both test dbnull on value cells (used above in pricevalidation):
' helper function convert dbnull private function safeconvert(v object) double if system.dbnull.value.equals(v) return 0 else dim d double = 0 if double.tryparse(v.tostring, d) end if return d end if end function
it work on cells have quantity or price not item code (text). whenever find typing same code on , on (and over), stop , better way.
Comments
Post a Comment