Windows Form-----Content (5)

Source: Internet
Author: User

Level three linkage under the same table:

Code:

Class DBconnection
{
Public Const string CONNECTIONSTRING = "server=.; database=mydb;uid=sa;pwd=5587725 ";
}

Class Chinastates
{
public string AreaCode {get; set;}
public string AreaName {get;set;}
public string Parentareacode {get; set;}
}

Class CHIANSTATESDA
{
Private SqlConnection _conn;
Private SqlCommand _cmd;
Private SqlDataReader _dr;
Public Chianstatesda ()
{
_conn = new SqlConnection (dbconnection.connectionstring);
_cmd = _conn.createcommand ();
}
Public list<chinastates> Select (string parentareacode)
{
list<chinastates> list = new list<chinastates> ();
_cmd.commandtext = "SELECT * from chinastates where [email protected]";
_cmd.parameters.clear ();
_cmd.parameters.addwithvalue ("@parentareacode", Parentareacode);
Try
{
_conn.open ();
_DR = _cmd.executereader ();
while (_DR. Read ())
{
Chinastates data = new Chinastates ();
Data. AreaCode = _dr["AreaCode"]. ToString ();
Data. AreaName = _dr["AreaName"]. ToString ();
Data. Parentareacode = _dr["Parentareacode"]. ToString ();
List. ADD (data);
}
}
Finally
{
_conn.close ();
}
return list;
}

public partial class Form1:form
{
Public Form1 ()
{
InitializeComponent ();
}
private void Fillprov ()
{
Fetch data
list<chinastates> list = new Chianstatesda (). Select ("0001");
Fill it in.
Cmbprov.datasource = list;
Cmbprov.displaymember = "AreaName";
Cmbprov.valuemember = "AreaCode";
}
private void Fillcity ()
{
String prt = (Cmbprov.selecteditem as chinastates). AreaCode;
list<chinastates> list = new Chianstatesda (). Select (PRT);
Cmbcity.datasource = list;
Cmbcity.displaymember = "AreaName";
Cmbcity.valuemember = "AreaCode";
}
private void Fillcounty ()
{
String prt = "";
if (cmbcity.selecteditem!=null)
{
PRT = (Cmbcity.selecteditem as chinastates). AreaCode;
}
list<chinastates> list = new Chianstatesda (). Select (PRT);
Cmbcounty.datasource = list;
Cmbcounty.displaymember = "AreaName";
Cmbcounty.valuemember = "AreaCode";
}
private void Form1_Load (object sender, EventArgs e)
{
Fillprov ();
Fillcity ();
Fillcounty ();
}

private void Cmbprov_selectedindexchanged (object sender, EventArgs e)
{
Fillcity ();
Fillcounty ();
}

private void Cmbcity_selectedindexchanged (object sender, EventArgs e)
{
Fillcounty ();
}
}

Windows Form-----Content (5)

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.