c# - Save ID instead of Name -


i have stored country name. instead of that, want store country id.

here code:-

if (!string.isnullorempty(mkey))         {             insertupdatequery = "update b_order_new set shipname = :shipname, shipcity = :shipcity, shipaddress = :shipaddress, " +                                  "shipcountry = :shipcountry, orderdate = :orderdate, sent = :sent mkey = :mkey";         }         else         {             insertupdatequery = "insert b_order_new (mkey, shipname, shipcity, shipaddress, shipcountry, orderdate, sent) " +                                  "values(:mkey, :shipname, :shipcity, :shipaddress, :shipcountry, :orderdate, :sent)";         }          oraclecommand cmd = new oraclecommand(insertupdatequery, myconn);          var orderedon = datetime.parseexact(orderdate, "dd/mm/yyyy", null);          cmd.parameters.add("mkey", oracletype.number).value = decimal.parse(mkey).tostring();         cmd.parameters.add("shipname", oracletype.varchar).value = shipname;         cmd.parameters.add("shipcity", oracletype.varchar).value = shipcity;         cmd.parameters.add("shipaddress", oracletype.varchar).value = shipaddress;         cmd.parameters.add("shipcountry", oracletype.varchar).value = shipcountry;         cmd.parameters.add("orderdate", oracletype.datetime).value = orderedon;         cmd.parameters.add("sent", oracletype.char).value = true; } 

also see select query how binding it.

<asp:sqldatasource id="sdcombo" runat="server" connectionstring="<%$ connectionstrings:oracleconn %>"     providername="<%$ connectionstrings:oracleconn.providername %>" selectcommand="select country_id, country_name country_test"> </asp:sqldatasource> 

my gridview binding dropdownlist

<obout:combobox runat="server" id="comboboxeditor" folderstyle="combobox/styles/premiere_blue"             width="100%" height="150" menuwidth="175" datasourceid="sdcombo" datatextfield="country_name"             datavaluefield="country_name" openonfocus="false">             <clientsideevents onblur="persistfieldvalue" onopen="combobox_open" />         </obout:combobox> 

replace combobox's datavaluefield="country_name" datavaluefield="country_id", load country_id combobox, can assign combobox's selectedvalue shipcountry variable, storing country id.

edit: can assign as:

shipcountry=comboboxeditor.selectedvalue; cmd.parameters.add("shipcountry", oracletype.varchar).value = shipcountry; 

change combobox's script bellow:

<obout:combobox runat="server" id="comboboxeditor" folderstyle="combobox/styles/premiere_blue" width="100%" height="150" menuwidth="175" datasourceid="sdcombo"  datatextfield="country_name" datavaluefield="country_id" openonfocus="false">  <clientsideevents onblur="persistfieldvalue" onopen="combobox_open" /> </obout:combobox> 

Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -