//Load event for the current form Private voidProvinceandcity_load (Objectsender, EventArgs e) { //Connection String stringstrconn ="Data Source=.;i Nitial catalog=province; User Id=sa; Pwd=ok"; //Connection ObjectSqlConnection conn =NewSqlConnection (strconn); //DataSet ObjectDataSet ds =NewDataSet (); //Query Province Statement stringsql ="SELECT * from province"; SqlDataAdapter Adapter=NewSqlDataAdapter (Sql,conn); Adapter. Fill (DS,"Province"); //bind the province's data to a drop-down box in the province This. Cboprovince.datasource = ds. tables["Province"]; This. Cboprovince.valuemember ="ID"; This. Cboprovince.displaymember ="Provincename"; //get the province number intid = Convert.ToInt32 ( This. Cboprovince.selectedvalue); //Search Cities by province numbersql ="SELECT * from city WHERE proid="+ID; Adapter=NewSqlDataAdapter (Sql,conn); Adapter. Fill (DS," City"); //will find out the city bound in the City drop-down box This. Cbocity.datasource = ds. tables[" City"]; This. Cbocity.valuemember ="ID"; This. Cbocity.displaymember ="CityName"; //Get City Number intCityid = Convert.ToInt32 ( This. Cbocity.selectedvalue); //Search Districts by city numbersql ="SELECT * from county WHERE cityid="+Cityid; Adapter=NewSqlDataAdapter (SQL, conn); Adapter. Fill (DS,"County"); //The counties to be found are bound in the county drop-down box This. Cbocounty.datasource = ds. tables["County"]; This. Cbocounty.valuemember ="ID"; This. Cbocounty.displaymember ="Countyname"; } //events in the province drop-down box Private voidCboprovince_selectionchangecommitted (Objectsender, EventArgs e) { stringstrconn ="Data Source=.;i Nitial catalog=province; User Id=sa; Pwd=ok"; SqlConnection Conn=NewSqlConnection (strconn); DataSet DS=NewDataSet (); //get the province number intid = Convert.ToInt32 ( This. Cboprovince.selectedvalue); //Search Cities by province number stringsql ="SELECT * from city WHERE proid="+ID; SqlDataAdapter Adapter=NewSqlDataAdapter (SQL, conn); Adapter. Fill (DS," City"); //will find out the city bound in the City drop-down box This. Cbocity.datasource = ds. tables[" City"]; This. Cbocity.valuemember ="ID"; This. Cbocity.displaymember ="CityName"; } //City drop-down box events Private voidCbocity_selectionchangecommitted (Objectsender, EventArgs e) { stringstrconn ="Data Source=.;i Nitial catalog=province; User Id=sa; Pwd=ok"; SqlConnection Conn=NewSqlConnection (strconn); DataSet DS=NewDataSet (); //Get City Number intCityid = Convert.ToInt32 ( This. Cbocity.selectedvalue); //Search Districts by city number stringsql ="SELECT * from county WHERE cityid="+Cityid; SqlDataAdapter Adapter=NewSqlDataAdapter (SQL, conn); Adapter. Fill (DS,"County"); //The counties to be found are bound in the county drop-down box This. Cbocounty.datasource = ds. tables["County"]; This. Cbocounty.valuemember ="ID"; This. Cbocounty.displaymember ="Countyname"; }
ComboBox, three-level linkage menu, new entry point small white, some code needs to be optimized, big God do not spray