sql - Take combobox SelectedIndex data and use in SELECT Query - VB.net -


i'm little desperate, hence why i'm here! i'm quite new programming , have been given assignment need use range of sql queries generate simple html report table. there user input, them selecting clinicid combobox , clicking button generate report.

basically, have combobox have populated 'clinicid', below. have made sure selectedindex working. need somehow use in sql query method have provided below.

public class frmreport1 'set lsdata clinics table dim lsdata list(of hashtable)   'on form load private sub frmreport1_load(sender object, e eventargs) handles mybase.load      cboclinicid.dropdownstyle = comboboxstyle.dropdownlist      'instantiate new cliniccontroller object     dim ccontroller cliniccontroller = new cliniccontroller      'load clinicid     lsdata = ccontroller.findid()      each clinic in lsdata         cboclinicid.items.add(cstr(clinic("clinicid")))     next  end sub  'selected index  private sub cboclinicid_selectedindexchanged(sender object, e eventargs) handles cboclinicid.selectedindexchanged     dim selectedindex integer = cboclinicid.selectedindex     dim selecteditem object = cboclinicid.selecteditem      'print in debug window     debug.print("selected clinicid: " & selecteditem.tostring())     debug.print("selected clinicid index: " & selectedindex.tostring())      dim htdata = lsdata.item(selectedindex)   end sub 

sql query method - **note, i'm pulling 2 different tables:

where '?' is, assume have work in 'selecteditem' have no idea how!

desired result: html table outputted these 3 selected fields.

public class clinicordercontroller  public const connection_string string = "provider=microsoft.ace.oledb.12.0;data source=pharmdb.accdb"  'dim ccontroller cliniccontroller = new cliniccontroller 'dim ocontroller ordercontroller = new ordercontroller  public function findclinicorder() list(of hashtable)      'instantiates connection object     dim oconnection oledbconnection = new oledbconnection(connection_string)     'instantiates list of hashtables     dim lsdata new list(of hashtable)      try         debug.print("connection string: " & oconnection.connectionstring)          oconnection.open()         dim ocommand oledbcommand = new oledbcommand         ocommand.connection = oconnection          'stored in commandtext property of command object         'select sql statement         ocommand.commandtext = "select clinics.clinic_id, orders.date_ordered, orders.total_price clinics, orders clinics.clinic_id = orders.clinic_id , clinics.clinic_id = ? order clinics.clinic_id"          'compiles prepared statement         'ocommand.prepare()         'executes sql statement , stores results in data reader object         dim odatareader = ocommand.executereader()          'process data set in hashtable         dim httempdata hashtable         while odatareader.read() = true             httempdata = new hashtable             httempdata("clinicid") = cstr(odatareader("clinic_id"))             httempdata("dateordered") = cstr(odatareader("date_ordered"))             httempdata("ordertotalprice") = cstr(odatareader("total_price"))             lsdata.add(httempdata)          loop          debug.print("the record was found.")      catch ex exception         debug.print("error:" & ex.message)         msgbox("an error occured!")             oconnection.close()     end try      'return list of hashtables calling function     return lsdata  end function 

really, appreciate here. ive been struggling more 8 hours (not joking - give permission laugh)

if understand correctly, want use dropdown selected item in where clause. achieve , revise joining using inner join on place filtering in where condition. hope code below help.

    select clinics.clinic_id,       , orders.date_ordered       , orders.total_price      clinics inner join orders on clinics.clinic_id = orders.clinic_id     clinics.clinic_id = selecteditem.tostring()     order clinics.clinic_id 

if selecteditem.tostring() did not work, can try selectedvalue


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -