ComboBox, three-level linkage menu, new entry point small white, some code needs to be optimized, big God do not spray

Source: Internet
Author: User

//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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.