当我从 datagridview 组合框中选择一个值以从数据库获取到 datagridview 文本框时,我想要。当我选择任何应该从数据库中获取单价的药物名称时,请参见图像。怎么可能呢?
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();