Based on the drop down value selected I have to retrieve other values from database in c# -


i have 2 drop down list category , product name. able populate values in product name list based on category selected. have populate other fields price , available quantity database based on product name selected.

this code category drop down

             private void makerorderfrm_load(object sender, eventargs e)              {                string selectcommand = "select distinct(productcategory)                  productstbl";                  try                  {                     conn.open();                  sqlcommand cmd = new sqlcommand(selectcommand, conn);                  sqldatareader reader = cmd.executereader();             while (reader.read())             {                 cmbcategory.items.add(reader[0].tostring());             }              reader.close();             conn.close();             }         catch (sqlexception)         {             messagebox.show("can't show categories");          } 

this code product name drop down list

            private void cmbcategory_selectedindexchanged(objectsender,              eventargs e)             {              conn.close();            cmbprodname.items.clear();             string selectcommand2 = "select productname productstbl              productcategory=@productcategory";            try            {             conn.open();             sqlcommand cmd = new sqlcommand(selectcommand2, conn);             cmd.parameters.addwithvalue("@productcategory",             cmbcategory.text);              sqldatareader reader =              cmd.executereader(commandbehavior.closeconnection);             while (reader.read())             {                 cmbprodname.items.add(reader[0].tostring());             }             //cmbcategory.selectedindex = 0;             reader.close();             }              catch (sqlexception)              {             messagebox.show("can't show categories");                 }               } 

now i'm unable fetch fields price,available quantity based on product name selected

                private void cmbprodname_selectedindexchanged(object sender,                 eventargs e)                {                  string selectcommand2 = "select productprice,productquant                 productstbl productname=@productname";                  try                  {                   conn.open();                   sqlcommand cmd = new sqlcommand(selectcommand2, conn);                   cmd.parameters.addwithvalue("@productprice",                     txtproductprice.text);                    cmd.parameters.addwithvalue("@productquant",                      txtavblqty.text);                        }                    catch (sqlexception)                        {                      messagebox.show("can't show categories");                           }                          } 


Comments

Popular posts from this blog

javascript - Create a stacked percentage column -

Optimising Firebase database by automatically overwriting data -

javascript - Angular UI-Grid customTemplate directive causing rows to load slowly/? -