.net - get multiple values form the database and show in combo box and different text boxes when the index change c# -


   try         {            // var model =execute.q"select product.id, product.productname, product.unitid, product.productcode, units.name product inner join units on product.unitid = units.id";              string query1 = "select product.id, product.productname, product.unitid, product.productcode, units.name product inner join units on product.unitid = units.id";             command = dbconnectivity.getcommandforquery(query1, connection);             dataset = new dataset();             adapter = new sqldataadapter(command);             adapter.fill(dataset);             int reslut = command.executenonquery();             this.cbproductname.displaymember = "productname";             this.cbproductname.valuemember = "id";             datarow = dataset.tables[0].newrow();             datarow["productname"] = "select product";             dataset.tables[0].rows.insertat(datarow, 0);             this.cbproductname.datasource = dataset.tables[0];         }          catch (exception ex)         {             console.writeline(ex.message);          }  private void cbproductname_selectedindexchanged(object sender, eventargs e)     {         if (this.cbproductname.selectedvalue != null)         {             txtprocode.text = this.cbproductname.selectedvalue.tostring();          }     } 

i want show product code , unit name in text boxes against id in product table , on change on selected index in combo box cbproductname. query give me values unable show in form.

you can change sql statement include informations need.

like:

select product.productname + ' ' + product.productcode + ' ' + units.name  showtext, product.id, product.productname, product.unitid, product.productcode, units.name product inner join units on product.unitid = units.id 

change cbproductname_selectedindexchanged method to:

datarow row = this.cbproductname.selecteditem datarow; if (row != null) {   txtprocode.text = row["showtext"].tostring(); } 

the combobox bound dataset contains datarow elements.


Comments

Popular posts from this blog

node.js - Mongoose: Cast to ObjectId failed for value on newly created object after setting the value -

gradle error "Cannot convert the provided notation to a File or URI" -

python - NameError: name 'subprocess' is not defined -