ComboBox1_SelectedIndexChanged method (provincial/municipal linkage project exercise)
In the defined SQL statement, you want to use comboBox1.SelectedValue defined earlier to query the joined fields in another table by obtaining its value other than dispvalue or Text. However, the problem arises, will prompt:
650) this. width = 650; "title =" not named. GIF "src =" http://www.bkjia.com/uploads/allimg/131228/19502K123-0.gif "orgsrc =" http://www.bkjia.com/uploads/allimg/131228/19502K123-0.gif "/> later after debugging, the problem race in the order of Data bound to the control, the code is changed to the following:
SqlHelper sh = new SqlHelper ();
String SQL = "select provinceid, provinceName from s_province ";
SqlConnection conn = new SqlConnection (strcon );
Conn. Open ();
DataTable dt = sh. ExecuteDataAdpter (SQL, strcon );
ComboBox1.DisplayMember = "provinceName ";
ComboBox1.ValueMember = "provinceid ";
// The value must be assigned first. Otherwise, an error occurs and the System. Data. DataRowView cannot be bound to an identifier consisting of multiple parts"
ComboBox1.DataSource = dt;
* Note: This method only applies to the combobox#selectedindexchanged method.
The comboBox1_SelectedValueChanged method does not have this problem.
This article is from the "C learning" blog, please be sure to keep this source http://wjmks.blog.51cto.com/3985820/1289576