vb.net - Last 'OR' statement Ignored in OLEDB command -


i'm trying filter oledb command having multiple 'or' statements work on single database field last in chain gets ignored , doesn't return anything.

i have work around @null request returns "dbnull.value" if remove "[doctype] = @null" below ignores "[doctype] = doctype3"

& "where [doctype] = @doctype or [doctype] = @doctype2 or [doctype] = @doctype3 or [doctype] = @null " _ 

i can increase or decrease 'or statements' last 'or statement' ignored.

i've tried putting 'or statements' in brackets returns nothing, or i'm doing wrong.

i'm looking why last 'or statement' ignored in oledbcommand string if can improve code i've wrote please do, explain me why/how.

where used (every other value has dbnull.value testing purposes)

            f_doctype = "ms"             f_doctype2 = "tms"             f_doctype3 = "cs"              cmdarefresh.parameters             .addwithvalue("doctype", ctype(f_doctype, string))             .addwithvalue("doctype2", ctype(f_doctype2, string))             .addwithvalue("doctype3", ctype(f_doctype3, string))             .addwithvalue("null", dbnull.value)             .addwithvalue("docnum", dbnull.value)             .addwithvalue("docrev", dbnull.value)             .addwithvalue("matname", dbnull.value)             .addwithvalue("status", dbnull.value)             .addwithvalue("actionreq", dbnull.value)             .addwithvalue("createdby", dbnull.value)             .addwithvalue("createddate", dbnull.value)             .addwithvalue("finalby", dbnull.value)             .addwithvalue("finaldate", dbnull.value)             end          dim cmdrefresh new oledbdataadapter(cmdarefresh)          'open connection         myconnection.open()          'read , fill dataset gridview         cmdrefresh.fill(dsrefresh, tbl_string.tablename)          'close connection         myconnection.close()  'fill datagrid values database , alter column headers match criteria         dg_speclog             .datasource = dsrefresh.tables(0)             .rowheadersvisible = false             .columns(0).headercell.value = "category"             ...         end 

full 'oledbcommand' creation

dim cmdarefresh oledbcommand = new oledbcommand(" select [doctype], [docnum], [docrev], [matname], [status], [actionreq], [createdby], [createddate], [finalby], [finaldate] " _                                                               & "from " & tbl_string.tablename & " " _                                                               & "where [doctype] = @doctype or [doctype] = @doctype2 or [doctype] = @doctype3 or [doctype] = @null " _                                                               & "and [docnum] = @docnum " _                                                               & "and [docrev] = @docrev " _                                                               & "and [matname] = @matname " _                                                               & "and [status] = @status " _                                                               & "and [actionreq] = @actionreq " _                                                               & "and [createdby] = @createdby " _                                                               & "and [createddate] = @createddate " _                                                               & "and [finalby] = @finalby " _                                                               & "and [finaldate] = @finaldate " _                                                               & "order [docnum] asc, [docrev] asc " _                                                               , myconnection) 

you need use is null check null values (in most, perhaps all, databases, null not equal null, need use is operator instead). means don't need parameters.

depending on how intend combine [doctype] null check other null checks, may need wrap ors in parentheses, since and may have higher precedence or.

dim cmdarefresh oledbcommand = new oledbcommand(     " select [doctype], [docnum], [docrev], [matname], [status], [actionreq], [createdby], [createddate], [finalby], [finaldate] " _     & "from " & tbl_string.tablename & " " _     & "where ([doctype] = @doctype or [doctype] = @doctype2 or [doctype] = @doctype3 or [doctype] null) " _     & "and [docnum] null " _     & "and [docrev] null " _     & "and [matname] null " _     & "and [status] null " _     & "and [actionreq] null " _     & "and [createdby] null " _     & "and [createddate] null " _     & "and [finalby] null " _     & "and [finaldate] null " _     & "order [docnum] asc, [docrev] asc " _     , myconnection) 

if the[doctype] null check belongs other null checks don't need parens.


Comments

Popular posts from this blog

java - pagination of xlsx file to XSSFworkbook using apache POI -

Unlimited choices in BASH case statement -

apache - How do I stop my index.php being run twice for every user -