gridview - how to check if the cell value is nothing or not in vb.net? -



using grid view in vb.net.
here code...

if not datagridview1.selectedrows.count = 0                 = datagridview1.selectedrows(0).index                 if datagridview1.rows(i).cells(0).value <> nothing                     namebox.text = trim(datagridview1.rows(i).cells(0).value)                     salarybox.text = datagridview1.rows(i).cells(1).value                 end if end if 

now if cell has nothing in show exception....
this...

operator '<>' not defined type 'dbnull' , 'nothing'. 

this code called when selected cell changed.
trying values of selected cell , put in in 1 text box.

you don't want use <> operator, should value isnot nothing check if isnot nothing or inversely is nothing check if value is nothing.

also reason there no comparer dbnull , nothing types if case need check see both.

if value isnot nothing andalso value <> dbnull.value     ''#do  end if 

Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -