inventory management - SQL Troubleshooting in VB.Net -


alright, here issue.

working on inventory control program, , got done, when wild bug appears. system check out item, not check in, though throws proper messages check item in.

what's worse, sql statement encapsulated in try-catch class , acts if nothing wrong, , not throw exception.

and functional build, not streamlined one, looks little rough.

the statement in question is:

dim olecheckin new oledbcommand("update assets set [checked out]='checked in' [id number]=" + sbarcode + "", oledbconn)

i sure very obvious, have been rebuilding , staring @ long, glossing on glaring hole in it.

option strict on imports system.data imports system.data.oledb public class form1 public empidflag boolean public itembcode boolean public checkflag boolean public dempid double public sempid string public dbempid double public dbarcode double public sbarcode string public sfirstname string public slastname string public sfullname string public sitem string public scheckedout string public scheckedoutby string public oledbconn oledb.oledbconnection = new oledb.oledbconnection("provider=microsoft.ace.oledb.12.0; data source = c:\users\rcassel\documents\visual studio 2012\projects\inventory control\inventory control\inventory control2.accdb;")   private sub textbox1_lostfocus(sender object, e eventargs) handles textbox1.lostfocus     dempid = (val(textbox1.text))      'checks see if entered badge     if dempid = nothing         msgbox("you must scan badge!", msgboxstyle.okonly)         textbox1.focus()     else         sempid = dempid.tostring         'fire query database         try             oledbconn.open()             dim oleemp new oledbcommand("select [first name],[last name],[employee id] contacts [employee id]=" + sempid + "", oledbconn)              dim r1 oledbdatareader = oleemp.executereader()              while r1.read()                 sfirstname = cstr(r1("first name"))                 slastname = cstr(r1("last name"))                 dbempid = cint(r1("employee id"))             end while              r1.close()         catch ex exception             'msgbox("cannot pull data." & vbcrlf & ex.message)         end try          if dbempid = nothing             msgbox("you not authorised use device. activity has been logged.", msgboxstyle.okonly)          else             me.listbox1.items.add(sfirstname)             me.listbox1.items.add(slastname)             me.listbox1.items.add(sempid)             textbox2.focus()         end if          oledbconn.close()     end if  end sub  'item barcode 'private sub textbox2_lostfocus(sender object, e eventargs) handles textbox2.lostfocus private sub textbox2_keypress(byval sender object, byval e system.windows.forms.keypresseventargs) handles textbox2.keypress     dbarcode = (val(textbox2.text))     if e.keychar = microsoft.visualbasic.chrw(keys.enter)          sbarcode = dbarcode.tostring()         oledbconn.open()         try             dim oleitem new oledbcommand("select [item],[checked out],[checked out last by] assets [id number]=" + sbarcode + "", oledbconn)             dim r2 oledbdatareader = oleitem.executereader()              while r2.read()                 sitem = cstr(r2("item"))                 scheckedout = cstr(r2("checked out"))                 scheckedoutby = cstr(r2("checked out last by"))              end while             itembcode = true              'set checkout flag, called later check in/check out button             if scheckedout = "checked out"                 checkflag = true             end if                  r2.close()         catch ex exception             msgbox("barcode invalid." & vbcrlf & ex.message)             itembcode = false         end try         if itembcode = true             me.listbox2.items.add(sitem)             me.listbox2.items.add(scheckedout)             me.listbox2.items.add(scheckedoutby)         end if         oledbconn.close()      end if end sub  private sub form1_load(sender object, e eventargs) handles mybase.load     textbox1.focus() end sub  'this "check in" button private sub button2_click(sender object, e eventargs) handles button2.click     if itembcode = false         msgbox("you must have valid item barcode!", msgboxstyle.okonly)         textbox2.focus()     else         if checkflag             try                 oledbconn.open()                     dim olecheckin new oledbcommand("update assets set [checked out]='checked in' [id number]=" + sbarcode + "", oledbconn)                      msgbox("this item has been checked in!", msgboxstyle.okonly)                 catch ex exception                     msgbox("barcode invalid." & vbcrlf & ex.message)                     itembcode = false                 end try         else             msgbox("this item checked in!", msgboxstyle.okonly)             textbox2.focus()         end if     end if     oledbconn.close() end sub  'this "check out" button private sub button3_click(sender object, e eventargs) handles button3.click     if itembcode = false         msgbox("you must have valid item barcode!", msgboxstyle.okonly)         textbox2.focus()     else         if checkflag = false             try                 sfullname = string.format("{0} {1}", sfirstname, slastname)                 oledbconn.open()                 dim olecheckout new oledbcommand("update assets set [checked out]='checked out',[checked out last by] ='" + sfullname + "' [id number]=" + sbarcode + "", oledbconn)                  msgbox("this item has been checked out!", msgboxstyle.okonly)              catch ex exception                 msgbox("barcode invalid." & vbcrlf & ex.message)                 itembcode = false             end try         else             msgbox("this item checked out!", msgboxstyle.okonly)             textbox2.focus()         end if     end if     oledbconn.close() end sub end class 

you never execute update commands:

olecheckin.executenonquery()  olecheckout.executenonquery() 

also, use parameters. exposing system sql injection.


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -