How to fetch data from database textbox when combox value is selected in datagridview

Posted by Megan00 under Sql Server on 7/25/2012 | Points: 10 | Views : 1576 | Status : [Member] | Replies : 0
When I choose a value from a datagridview combo box , I want to fetch data from the database into a datagridview textbox. See in the image when I choose any medicine name that unitprice should be fetched from the database. How can that be done?

             SqlConnection con = new SqlConnection(connection string);


SqlDataAdapter adp = new SqlDataAdapter("select quantity,unitprice,totalprice from stock where medicinename='" + dataGridView1.Columns[0].ToString() + "' ", con);
DataSet ds = new DataSet();
dataGridView1.DataSource = ds;

dataGridView1.Columns[1].DataPropertyName = "quantity";
dataGridView1.Columns[2].DataPropertyName = "unitprice";
dataGridView1.Columns[3].DataPropertyName = "totalprice";

Never give up! Smile to the world!


(No response found.)

Login to post response