zoukankan      html  css  js  c++  java
  • 2017-5-7 三级联动

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows.Forms;
    using 三级联动.App_code;
    
    namespace 三级联动
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
                bind("0001",comboBox1);
                bind(comboBox1.SelectedValue.ToString(),comboBox2);
                bind(comboBox2.SelectedValue.ToString(),comboBox3);
                
            }
            public void bind(string pcode, ComboBox cb)
            {
    
                List<chinastate> clist = new chinastatedata().select(pcode);
                cb.DataSource = clist;
                cb.DisplayMember = "AreaName";
                cb.ValueMember = "AreaCode";
            }
    
            private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
            {
                bind(comboBox1.SelectedValue.ToString(), comboBox2);
                if (comboBox2.SelectedValue!=null)
                {
                bind(comboBox2.SelectedValue.ToString(), comboBox3);
                }
            }
    
            private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
            {
                bind(comboBox2.SelectedValue.ToString(), comboBox3);
            }
        }
    }

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    
    namespace 三级联动.App_code
    {
       public  class chinastate
        {
            private string _AreaCode;
    
            public string AreaCode
            {
                get { return _AreaCode; }
                set { _AreaCode = value; }
            }
            private string _AreaName;
    
            public string AreaName
            {
                get { return _AreaName; }
                set { _AreaName = value; }
            }
            private string _ParentAreaCode;
    
            public string ParentAreaCode
            {
                get { return _ParentAreaCode; }
                set { _ParentAreaCode = value; }
            }
        }
    }
    using System;
    using System.Collections.Generic;
    using System.Data.SqlClient;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    
    namespace 三级联动.App_code
    {
        public class chinastatedata
        { 
            SqlConnection conn=null;
            SqlCommand cmd=null;
    
            public chinastatedata()
         {
             conn = new SqlConnection("server=.;database=data0216;user=sa;pwd=123");
             cmd = conn.CreateCommand();
         }
    
            public List<chinastate> select(string pcode) 
            {
                List<chinastate> clist = new List<chinastate>();
                cmd.CommandText = "select * from ChinaStates where ParentAreaCode=@a";
                cmd.Parameters.Clear();
                cmd.Parameters.AddWithValue("@a",pcode);
                conn.Open();
                SqlDataReader dr = cmd.ExecuteReader();
                while(dr.Read())
                {
                    chinastate c = new chinastate();
                    c.AreaCode = dr[0].ToString();
                    c.AreaName = dr[1].ToString();
                    c.ParentAreaCode = dr[2].ToString();
                    clist.Add(c);
    
                }
                conn.Close();
    
                return clist;
            }
    
    
    
    
        }
        
    }
  • 相关阅读:
    枚举与常量需要注意的一个问题
    parted分区用法
    Linux下常用服务的端口号
    NFS服务
    mount用法
    Rsync服务部署
    常见的RAID级别
    SQL注入语句 (很全)
    数据库被注入daxia123或cn.jxmmtv.com原因及解决办法
    StringTemplate.net模板技术用法
  • 原文地址:https://www.cnblogs.com/zhengqian/p/6822482.html
Copyright © 2011-2022 走看看