sql - VB -- How to test for value not in dropdown -


i have large vb/sql application have created problem in. have table of procedures have active flag on them. flag can toggled through user screen. other screens access same table populate dropdowns. values stored in table id field (pk). problem have selecting dropdown values based on active flag. if select record has procedure stored in has been made inactive, old object not set instance.... error.

what want able check value in record when populating dropdown , allow record displayed bypassing sql error , showing dropdown value blank while not altering record itself. hope i'm making sense. code below -- pretty vanilla stuff, i'm in app programming after being sysadmin 20 years , i'm still rusty.

library code

public function getdropdownlist(byval strdropdownlist string, _                                 byref objsession system.web.sessionstate.httpsessionstate) string      dim strsql string = ""      select case strdropdownlist          case "surgicalprocedure_id"             strsql = "select [id]=0,[description]='' " _                    & "union " _                    & "select [id],[description] " _                    & "from dbo.viw_list_surgicalprocedures " _                    & "where isnull(active,0) = 1 " _                    & "order [description] asc" 

vb code-behind

        objsqlcommand             .connection = mobjsqlconnection             .commandtext = "select * " _                          & "from dbo.viw_tblcaseprocedure " _                          & "where [id] = " & session("case_id").tostring             .commandtype = commandtype.text         end          objsqldataadapter = new sqldataadapter(objsqlcommand)          objsqldataadapter.fill(objsqldataset)          objsqldatarow = objsqldataset.tables(0).rows(0)          objdropdownlist = me.surgicalprocedure_id         strstringvalue = objsqldatarow("surgicalprocedure_id").tostring()         if strstringvalue = "" strstringvalue = "0"         objdropdownlist.items.findbyvalue(strstringvalue).selected = true 

thanks in advance suggestions, joel

i'm not entirely clear on approach, @ guess, problem seems @ line:

objdropdownlist.items.findbyvalue(strstringvalue).selected = true 

the start instead avoid object not set error:

dim ddlitem listitem = objdropdownlist.items.findbyvalue(strstringvalue) if ddlitem nothing     ' insert 'blank item' code here else     ddlitem.selected = true endif 

hope helps!


Comments

Popular posts from this blog

c# - how to write client side events functions for the combobox items -

exception - Python, pyPdf OCR error: pyPdf.utils.PdfReadError: EOF marker not found -