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);
con.Open();
SqlDataAdapter adp = new SqlDataAdapter("select quantity,unitprice,totalprice from stock where medicinename='" + dataGridView1.Columns[0].ToString() + "' ", con);
DataSet ds = new DataSet();
adp.Fill(ds);
dataGridView1.DataSource = ds;
dataGridView1.Columns[1].DataPropertyName = "quantity";
dataGridView1.Columns[2].DataPropertyName = "unitprice";
dataGridView1.Columns[3].DataPropertyName = "totalprice";
con.Close();
Never give up! Smile to the world!
http://excelcsharp.blog.com/