mysql - How to store a value from a database as a variable to use in an insert statement -


with dropdown box , button trying insert pharmacyid order table don't know how store pharmacyid variable read in other values getting. have stored rest sessions so:

protected sub btnconfirm_click(sender object, e eventargs) handles btnconfirm.click          ' dropdown pharmacy  somevariable = droppharm.selecteditem.value             dim patientid integer = session("patientid")         dim doctorid integer = session("doctorid")         dim pharmacyid integer ' pharmacy must stored(droppharm.selectedvalue  must selected value)         dim medicineid integer = session("medicineid")         dim dateordered date            ' how pharmacy id stored                 'select pharmacy_id pharmacy pharmname = '';  ??           dim query string = string.empty         query &= "insert order_pres (patientid, pharmacyid, medicineid, "         query &= "                     doctorid, dateordered)  "         query &= "values (@patientid, @medicineid, @pharmacyid, @doctorid, @dateordered)"            dim sqlcs string = configurationmanager.connectionstrings("surgeryconnectionstring").connectionstring          using conn new sqlconnection(sqlcs),               comm new sqlcommand(query, conn)             comm.parameters                    .add("@patientid", sqldbtype.int).value = session("patientid")                 .add("@doctorid", sqldbtype.int).value = session("doctorid")                 .add("@medicineid", sqldbtype.int).value = session("medicineid")                 .add("@pharmacyid", sqldbtype.int).value = session("pharmacyid")                 .add("@dateordered", sqldbtype.datetime).value = datetime.parse(dateordered)                end               try                 conn.open()                 dim rowinserted = comm.executenonquery()                 if rowinserted = 1                     lblconfirm.text = "order placed"                 else                     lblnoconfirm.text = "order not placed"                 end if             catch ex sqlexception                 lblnoconfirm.text = "unexpectd error: " & ex.message             end try          end using 

the pharmacyid appears on .aspx page dropdown , sql data source:

<asp:sqldatasource id="sqlpharm" runat="server" connectionstring="<%$ connectionstrings:surgeryconnectionstring %>" selectcommand="select distinct pharmacyid, pharmname pharmacy "></asp:sqldatasource>    <asp:dropdownlist id="droppharm" runat="server" datasourceid="sqlpharm" datatextfield="pharmname" datavaluefield="pharmacyid"></asp:dropdownlist>  

when value selected dropdown , button clicked have appearing on label @ moment, trying saved variable can read insery query

enter image description here

hopefully can help, thank you

you need pass value in correct sequence

dim query string = string.empty         query &= "insert order_pres (patientid, pharmacyid, medicineid, "         query &= "                     doctorid, dateordered)  "         query &= "values (@patientid, @medicineid, @pharmacyid, @doctorid, @dateordered)" 

will be

dim query string = string.empty         query &= "insert order_pres (patientid, pharmacyid, medicineid, "         query &= "                     doctorid, dateordered)  "         query &= "values (@patientid,@pharmacyid, @medicineid,  @doctorid, @dateordered)" 

this resolve problem


Comments

Popular posts from this blog

Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project.Error occurred in starting fork -

windows - Debug iNetMgr.exe unhandle exception System.Management.Automation.CmdletInvocationException -

configurationsection - activeMq-5.13.3 setup configurations for wildfly 10.0.0 -