在datagridview中选择组合框值时从数据库文本框中获取数据?

时间:2012-07-24 09:17:57

标签: c# sql-server database visual-studio-2008 datagridview

我想从datagridview组合框中选择一个值,从数据库中提取到datagridview文本框。当我选择任何药物名称时,请在图像中查看应从数据库中提取unitprice。怎么办?

 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();

enter image description here

0 个答案:

没有答案